#include #include #include #include #include #include #define TEST_Hex(FUNCTION) do { \ FUNCTION("", "", 0); \ FUNCTION("42", "\x42", 1); \ FUNCTION("42 00 FF AA 24", "\x42\x00\xff\xaa\x24", 5); \ FUNCTION("00 01 02 03 04 05 06 FF", "\x00\x01\x02\x03\x04\x05\x06\xff", 8); \ } while (0) #define TEST_byteArrayToString(STR, DATA, SIZE) \ EXPECT_EQ(STR, ScHex::byteArrayToString(std::string((char*)memcpy(new BYTE[SIZE], DATA, SIZE), SIZE))) TEST(Hex, ByteArrayToString) { TEST_Hex(TEST_byteArrayToString); } #define TEST_stringToByteArray(STR, DATA, SIZE) do { \ auto bytes = ScHex::stringToByteArray(STR); \ EXPECT_EQ(SIZE, bytes.size()); \ EXPECT_EQ(0, memcmp(bytes.data(), DATA, SIZE)); \ } while (0) TEST(Hex, StringToByteArray) { TEST_Hex(TEST_stringToByteArray); } TEST(Reader, Test1) { std::cout << "Ensure that at lest 1 reader is connected"; getchar(); EXPECT_TRUE(ScReader::establishContext()); auto readers = ScReader::getReaders(); EXPECT_GE(readers.size(), 1); for (auto reader : readers) { std::cout << reader->getName() << std::endl; } auto reader = readers[0]; EXPECT_TRUE(reader->connect()); auto res = reader->transmit(ScBasicCommand("94 A4 00 00 02 20 00 00")); EXPECT_NE(nullptr, res->getData().data()); auto resp = ScHex::byteArrayToString(res->getData()); std::cout << "Response (" << res->getData().size() << "): " << resp << std::endl; EXPECT_TRUE(reader->disconnect()); EXPECT_TRUE(ScReader::freeContext()); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); /*std::cout << ScReader::establishContext() << std::endl; auto readers = ScReader::getReaders(); for (auto reader : readers) { std::cout << reader->getName() << " "; std::cout << reader->connect() << " "; std::cout << reader->disconnect(); std::cout << std::endl; } std::cout << ScReader::freeContext() << std::endl; return 0;*/ }