Browse Source

tests

master
Robin Thoni 9 years ago
parent
commit
e9d3d9b118
3 changed files with 20 additions and 11 deletions
  1. 1
    0
      CMakeLists.txt
  2. 1
    1
      tests/CMakeLists.txt
  3. 18
    10
      tests/test_pcsc_cpp_tools.cpp

+ 1
- 0
CMakeLists.txt View File

@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8)
2 2
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
3 3
 project(pcsc_cpptools)
4 4
 find_package(PCSCLite REQUIRED)
5
+find_package(GTest REQUIRED)
5 6
 enable_testing()
6 7
 add_subdirectory(src)
7 8
 add_subdirectory(tests)

+ 1
- 1
tests/CMakeLists.txt View File

@@ -1,6 +1,6 @@
1 1
 enable_testing()
2 2
 include_directories(${CHECK_INCLUDE_DIRS})
3
-set(LIBS ${LIBS} pcsc_cpptools)
3
+set(LIBS ${LIBS} pcsc_cpptools gtest)
4 4
 include_directories(. ../src)
5 5
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -I/usr/include/PCSC -I${CMAKE_SOURCE_DIR}/src/include")
6 6
 add_executable(test_pcsc_cpp_tools test_pcsc_cpp_tools.cpp)

+ 18
- 10
tests/test_pcsc_cpp_tools.cpp View File

@@ -1,18 +1,26 @@
1 1
 #include <iostream>
2
+#include <string.h>
3
+#include <gtest/gtest.h>
2 4
 #include <ScHex.h>
3 5
 #include <ScReader.h>
4 6
 
5
-int main()
7
+#define TEST_byteArrayToString(STR, DATA, SIZE) \
8
+  EXPECT_EQ(STR, ScHex::byteArrayToString(ScByteArray((BYTE*)memcpy(new BYTE[SIZE], DATA, SIZE), SIZE)))
9
+
10
+TEST(Hex, ByteToString)
11
+{
12
+  TEST_byteArrayToString("", "", 0);
13
+  TEST_byteArrayToString("42", "\x42", 1);
14
+  TEST_byteArrayToString("42 00 FF AA 24", "\x42\x00\xff\xaa\x24", 5);
15
+  TEST_byteArrayToString("00 01 02 03 04 05 06 FF", "\x00\x01\x02\x03\x04\x05\x06\xff", 8);
16
+}
17
+
18
+int main(int argc, char* argv[])
6 19
 {
7
-  auto bytes = new BYTE[5];
8
-  bytes[0] = 0x42;
9
-  bytes[1] = 0x00;
10
-  bytes[2] = 0xff;
11
-  bytes[3] = 0xaa;
12
-  bytes[4] = 0x24;
13
-  std::cout << "hex: " << ScHex::byteArrayToString(ScByteArray(bytes, 5)) << std::endl;
20
+  ::testing::InitGoogleTest(&argc, argv);
21
+  return RUN_ALL_TESTS();
14 22
 
15
-  std::cout << ScReader::establishContext() << std::endl;
23
+  /*std::cout << ScReader::establishContext() << std::endl;
16 24
   auto readers = ScReader::getReaders();
17 25
   for (auto reader : readers)
18 26
   {
@@ -22,5 +30,5 @@ int main()
22 30
     std::cout << std::endl;
23 31
   }
24 32
   std::cout << ScReader::freeContext() << std::endl;
25
-  return 0;
33
+  return 0;*/
26 34
 }

Loading…
Cancel
Save