Created
December 10, 2014 07:54
-
-
Save alyx/630346fe837318a16cd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "detect.hpp" | |
#include <gtest/gtest.h> | |
char useragents[][128] = { | |
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36", //0 Linux, Chrome, Desktop | |
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36", //1 OS X, Chrome, Desktop | |
"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25", //2 OS X, Safari, Mobile | |
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A", //3 OS X, Safari, Desktop | |
"Mozilla/5.0 (X11; Mageia; Linux x86_64; rv:10.0.9) Gecko/20100101 Firefox/10.0.9", //4 Linux, Firefox, Desktop | |
"Mozilla/5.0 (Android; U; Android; pl; rv:1.9.2.8) Gecko/20100202 Firefox/3.5.8", //5 Linux, Firefox, Mobile | |
"Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.9b5) Gecko/2008032620 Firefox/3.0b5", //6 Unix, Firefox, Desktop | |
"Mozilla/4.0 (compatible; MSIE 4.01; Mac_PowerPC)" //7 Mac OS, IE, Desktop | |
}; | |
TEST(UserAgentDetection, UnixOperatingSystem) { | |
// Detect SunOS | |
EXPECT_EQ(DETECT_OP_SYS_UNIX, detect::operating_system(std::string(useragents[6]))); | |
// Detect BSD | |
//EXPECT_EQ(0, 0); | |
// Detect IRIX | |
//EXPECT_EQ(0,0); | |
} | |
TEST(UserAgentDetection, LinuxOperatingSystem) { | |
// Detect Linux | |
EXPECT_EQ(DETECT_OP_SYS_LINUX, detect::operating_system(std::string(useragents[4]))); | |
// Detect Android | |
EXPECT_EQ(DETECT_OP_SYS_LINUX, detect::operating_system(std::string(useragents[5]))); | |
} | |
TEST(UserAgentDetection, MacOperatingSystem) { | |
// Detect Mac OS <10 (Mac_PowerPC) | |
EXPECT_EQ(DETECT_OP_SYS_MACOS, detect::operating_system(std::string(useragents[7]))); | |
// Detect Mac OS X | |
EXPECT_EQ(DETECT_OP_SYS_MACOS, detect::operating_system(std::string(useragents[3]))); | |
// Detect iPad | |
EXPECT_EQ(DETECT_OP_SYS_MACOS, detect::operating_system(std::string(useragents[2]))); | |
} | |
TEST(UserAgentDetection, OperaBrowser) { | |
} | |
TEST(UserAgentDetection, InternetExplorerBrowser) { | |
} | |
TEST(UserAgentDetection, FirefoxBrowser) { | |
} | |
TEST(UserAgentDetection, SafariBrowser) { | |
} | |
TEST(UserAgentDetection, ChromeBrowser) { | |
EXPECT_EQ(DETECT_BROWSER_CHROME, detect::browser(std::string(useragents[0]))); | |
EXPECT_EQ(DETECT_BROWSER_CHROME, detect::browser(std::string(useragents[1]))); | |
} | |
TEST(UserAgentDetection, MobileDevice) { | |
EXPECT_EQ(DETECT_DEVICE_MOBILE, detect::device(std::string(useragents[2]))); | |
EXPECT_EQ(DETECT_DEVICE_MOBILE, detect::device(std::string(useragents[5]))); | |
} | |
TEST(UserAgentDetection, DesktopDevice) { | |
EXPECT_EQ(DETECT_DEVICE_DESKTOP, detect::device(std::string(useragents[0]))); | |
EXPECT_EQ(DETECT_DEVICE_DESKTOP, detect::device(std::string(useragents[7]))); | |
EXPECT_EQ(DETECT_DEVICE_DESKTOP, detect::device(std::string(useragents[3]))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment