-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutest.cpp
More file actions
77 lines (69 loc) · 2.52 KB
/
utest.cpp
File metadata and controls
77 lines (69 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*!\file utest.cpp
* \brief Unit tests for ResPack
*
* This is a very simple unittest. Most of it is handled by the build system which uses
* the respack binary to generate a binary blob from the licensefile as this is a known
* contant.
*/
#include "respack.h"
#include "utest_res.h"
int upassed=0;
int ufailed=0;
/*!\brief Simplistic unittest
* \param Name Name of the test
* \param Result True if the test passed
*/
void test(const std::string &Name,const bool &Result){
printf(" %-75s%s\n",Name.c_str(),Result?"PASS":"FAIL");
if(Result){
upassed++;
}
else{
ufailed++;
}
}
/*!\brief Test basic functions like parsing
*/
void test_basic(){
printf("\nTesting basic functions:\n");
// String formatting
ResPack respack("x","y");
test("Format(\%02X,0) formats as expected",respack.Format("%02X",0)=="00");
test("Format(\%02X,0xFF) formats as expected",respack.Format("%02X",0xFF)=="FF");
test("Format(\%02X,0xFFFF) formats as expected",respack.Format("%02X",0xFFFF)=="FFFF");
test("Format(\%.2f,1.2345) formats as expected",respack.Format("%.2f",1.2345)=="1.23");
// Filename parsing
test("Parsing basename from test.sh",respack.ParseName("test.sh")=="test");
test("Parsing extension from test.sh",respack.ParseExt("test.sh")=="sh");
test("Parsing basename from /usr/bin/test.sh",respack.ParseName("/usr/bin/test.sh")=="test");
test("Parsing extension from /usr/bin/test.sh",respack.ParseExt("/usr/bin/test.sh")=="sh");
test("Parsing extension from /usr/bin/test",respack.ParseExt("/usr/bin/test")=="");
test("Parsing extension from /usr/bin.tmp/test",respack.ParseExt("/usr/bin.tmp/test")=="");
test("Parsing extension from /usr/bin.tmp/test.sh",respack.ParseExt("/usr/bin.tmp/test.sh")=="sh");
}
/*!\brief Test basic ResPack handling
*/
void test_respack(){
printf("\nTesting respack functions:\n");
UTestRes utestres;
test("One packed resource",utestres.Enumerate().size()==1);
test("Resource name is as expected",utestres.Enumerate()[0].name=="LICENSE");
test("Resource size is as expected",utestres.Enumerate()[0].size==1071);
}
/*!\brief Run baby! RUN!
*/
int main(){
printf("UTest %s\n",RESPACK_VERSION);
printf("ResPack unittest system\n");
printf("Vegard Fiksdal (C) 2026\n");
test_basic();
test_respack();
printf("\nPassed %d/%d tests\n",upassed,upassed+ufailed);
if(ufailed==0){
printf("All clear!\n");
}
else{
printf("Failed %d tests!\n",ufailed);
}
return ufailed;
}