浏览代码

Fixed binary Unit Test

Thomas Buck 10 年前
父节点
当前提交
dc3ffcdb41
共有 2 个文件被更改,包括 58 次插入14 次删除
  1. 1
    0
      ChangeLog.md
  2. 57
    14
      test/binary.cpp

+ 1
- 0
ChangeLog.md 查看文件

@@ -4,6 +4,7 @@
4 4
 
5 5
     [ 20140809 ]
6 6
     * Script Unit Test brings it’s own scripts to test
7
+    * Fixed binary Unit Test not deleting it’s tmp file in case of error
7 8
 
8 9
     [ 20140808 ]
9 10
     * Added unit test for file-system utils

+ 57
- 14
test/binary.cpp 查看文件

@@ -38,26 +38,69 @@ namespace {
38 38
         file.write(reinterpret_cast<char *>(&f2), sizeof(f2));
39 39
     }
40 40
 
41
-    //! \fixme Don't use assert(), as it will prevent removing the created test file!
42 41
     int test(const char *name) {
43 42
         BinaryFile file;
44
-        assertEqual(file.open(name), 0);
43
+        if (file.open(name) != 0) {
44
+            std::cout << "Error opening file " << name << std::endl;
45
+            return 1;
46
+        }
47
+
48
+        if (file.readU8() != 255) {
49
+            std::cout << "Error reading U8!" << std::endl;
50
+            return 2;
51
+        }
52
+
53
+        if (file.readU16() != 65535) {
54
+            std::cout << "Error reading U16!" << std::endl;
55
+            return 3;
56
+        }
57
+
58
+        if (file.readU32() != 707406378) {
59
+            std::cout << "Error reading U32!" << std::endl;
60
+            return 4;
61
+        }
62
+
63
+        if (file.readU64() != 1099511627775) {
64
+            std::cout << "Error reading U64!" << std::endl;
65
+            return 5;
66
+        }
67
+
68
+        if (file.read8() != -1) {
69
+            std::cout << "Error reading 8!" << std::endl;
70
+            return 6;
71
+        }
72
+
73
+        if (file.read16() != -420) {
74
+            std::cout << "Error reading 16!" << std::endl;
75
+            return 7;
76
+        }
77
+
78
+        if (file.read32() != -666) {
79
+            std::cout << "Error reading 32!" << std::endl;
80
+            return 8;
81
+        }
82
+
83
+        if (file.read64() != 4774451407313060418) {
84
+            std::cout << "Error reading 64!" << std::endl;
85
+            return 9;
86
+        }
45 87
 
46
-        assertEqual(file.readU8(), 255);
47
-        assertEqual(file.readU16(), 65535);
48
-        assertEqual(file.readU32(), 707406378);
49
-        assertEqual(file.readU64(), 1099511627775);
88
+        std::cout << "This test will fail on big-endian machines!" << std::endl;
50 89
 
51
-        assertEqual(file.read8(), -1);
52
-        assertEqual(file.read16(), -420);
53
-        assertEqual(file.read32(), -666);
54
-        assertEqual(file.read64(), 4774451407313060418);
90
+        if (file.readFloat() != f1) {
91
+            std::cout << "Error reading float1!" << std::endl;
92
+            return 10;
93
+        }
55 94
 
56
-        std::cout << "This test will fail on big-endian machines!" << std::endl;
57
-        assertEqual(file.readFloat(), f1);
58
-        assertEqual(file.readFloat(), f2);
95
+        if (file.readFloat() != f2) {
96
+            std::cout << "Error reading float2!" << std::endl;
97
+            return 11;
98
+        }
59 99
 
60
-        assertEqual(file.tell(), 38);
100
+        if (file.tell() != 38) {
101
+            std::cout << "Error, file position wrong!" << std::endl;
102
+            return 12;
103
+        }
61 104
 
62 105
         return 0;
63 106
     }

正在加载...
取消
保存