Quellcode durchsuchen

tests refactor

develop
Robin Thoni vor 8 Jahren
Ursprung
Commit
625b200c20
5 geänderte Dateien mit 69 neuen und 41 gelöschten Zeilen
  1. 3
    1
      tests/CMakeLists.txt
  2. 19
    0
      tests/Common.h
  3. 15
    0
      tests/Common.hxx
  4. 0
    40
      tests/test-main.cpp
  5. 32
    0
      tests/test-result.cpp

+ 3
- 1
tests/CMakeLists.txt Datei anzeigen

@@ -5,7 +5,9 @@ find_package (Threads)
5 5
 set(LIBS ${LIBS} gtest pthread rozitm)
6 6
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
7 7
 add_executable(test-main
8
-  test-main.cpp
8
+        Common.hxx
9
+        test-main.cpp
10
+        test-result.cpp
9 11
   )
10 12
 target_link_libraries(test-main ${LIBS})
11 13
 add_test(test-main ${CMAKE_CURRENT_BINARY_DIR}/test-main)

+ 19
- 0
tests/Common.h Datei anzeigen

@@ -0,0 +1,19 @@
1
+//
2
+// Created by robin on 5/10/16.
3
+//
4
+
5
+#ifndef ROZITM_COMMON_H
6
+#define ROZITM_COMMON_H
7
+
8
+#include <string>
9
+
10
+class Common
11
+{
12
+public:
13
+    template <class T>
14
+    static void testStream(const T& data, const std::string& ref);
15
+};
16
+
17
+#include "Common.hxx"
18
+
19
+#endif //ROZITM_COMMON_H

+ 15
- 0
tests/Common.hxx Datei anzeigen

@@ -0,0 +1,15 @@
1
+//
2
+// Created by robin on 5/10/16.
3
+//
4
+
5
+#include <sstream>
6
+#include <string>
7
+#include <gtest/gtest.h>
8
+#include "Common.h"
9
+
10
+template <class T>
11
+void Common::testStream(const T& data, const std::string& ref) {
12
+    std::ostringstream stream;
13
+    stream << data;
14
+    ASSERT_EQ(stream.str(), ref);
15
+}

+ 0
- 40
tests/test-main.cpp Datei anzeigen

@@ -1,47 +1,7 @@
1
-#include <iostream>
2
-#include <string.h>
3 1
 #include <gtest/gtest.h>
4
-#include "DBO/Result.h"
5
-
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)
30
-{
31
-    errno = 0;
32
-    testStream(ResultInt::strerror(), "Error: Success");
33
-    errno = EACCES;
34
-    testStream(ResultInt::strerror(), "Error: Permission denied");
35
-    errno = 0;
36
-}
37 2
 
38 3
 int main(int argc, char* argv[])
39 4
 {
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 5
     ::testing::InitGoogleTest(&argc, argv);
46 6
     return RUN_ALL_TESTS();
47 7
 }

+ 32
- 0
tests/test-result.cpp Datei anzeigen

@@ -0,0 +1,32 @@
1
+//
2
+// Created by robin on 5/10/16.
3
+//
4
+
5
+#include <gtest/gtest.h>
6
+#include "DBO/Result.h"
7
+#include "Common.h"
8
+
9
+TEST(Result, ok)
10
+{
11
+    Common::testStream(ResultInt::ok(42), "Success: 42");
12
+    Common::testStream(ResultInt::ok(0), "Success: 0");
13
+    Common::testStream(ResultBool::ok(true), "Success: 1");
14
+    Common::testStream(ResultBool::ok(false), "Success: 0");
15
+    Common::testStream(ResultDouble::ok(0.42), "Success: 0.42");
16
+    Common::testStream(ResultDouble::ok(-0.42), "Success: -0.42");
17
+}
18
+
19
+TEST(Result, error)
20
+{
21
+    Common::testStream(ResultInt::error("My error label"), "Error: My error label");
22
+    Common::testStream(ResultInt::error(""), "Error: Unknown error");
23
+}
24
+
25
+TEST(Result, strerror)
26
+{
27
+    errno = 0;
28
+    Common::testStream(ResultInt::strerror(), "Error: Success");
29
+    errno = EACCES;
30
+    Common::testStream(ResultInt::strerror(), "Error: Permission denied");
31
+    errno = 0;
32
+}

Laden…
Abbrechen
Speichern