Sfoglia il codice sorgente

Result DBO tests

develop
Robin Thoni 8 anni fa
parent
commit
eb13530eab
1 ha cambiato i file con 37 aggiunte e 7 eliminazioni
  1. 37
    7
      tests/test-main.cpp

+ 37
- 7
tests/test-main.cpp Vedi File

@@ -1,17 +1,47 @@
1 1
 #include <iostream>
2 2
 #include <string.h>
3 3
 #include <gtest/gtest.h>
4
-#include "DataAccess/Pcap.h"
4
+#include "DBO/Result.h"
5 5
 
6
-TEST(None, None)
6
+template <class T>
7
+void testStream(const T& data, const std::string& ref) {
8
+    std::ostringstream stream;
9
+    stream << data;
10
+    ASSERT_EQ(stream.str(), ref);
11
+}
12
+
13
+TEST(Result, ok)
14
+{
15
+    testStream(ResultInt::ok(42), "Success: 42");
16
+    testStream(ResultInt::ok(0), "Success: 0");
17
+    testStream(ResultBool::ok(true), "Success: 1");
18
+    testStream(ResultBool::ok(false), "Success: 0");
19
+    testStream(ResultDouble::ok(0.42), "Success: 0.42");
20
+    testStream(ResultDouble::ok(-0.42), "Success: -0.42");
21
+}
22
+
23
+TEST(Result, error)
24
+{
25
+    testStream(ResultInt::error("My error label"), "Error: My error label");
26
+    testStream(ResultInt::error(""), "Error: Unknown error");
27
+}
28
+
29
+TEST(Result, strerror)
7 30
 {
8
-  ASSERT_TRUE(true);
31
+    errno = 0;
32
+    testStream(ResultInt::strerror(), "Error: Success");
33
+    errno = EACCES;
34
+    testStream(ResultInt::strerror(), "Error: Permission denied");
35
+    errno = 0;
9 36
 }
10 37
 
11 38
 int main(int argc, char* argv[])
12 39
 {
13
-  Pcap pcap("eth0");
14
-  pcap.test();
15
-  ::testing::InitGoogleTest(&argc, argv);
16
-  return RUN_ALL_TESTS();
40
+//    std::cout << IResult::ok(42) << std::endl;
41
+//    std::cout << IResult::error("Test. error") << std::endl;
42
+//    errno = EACCES;
43
+//    std::cout << IResult::strerror() << std::endl;
44
+//    errno = 0;
45
+    ::testing::InitGoogleTest(&argc, argv);
46
+    return RUN_ALL_TESTS();
17 47
 }

Loading…
Annulla
Salva