-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.C
121 lines (100 loc) · 2.64 KB
/
test.C
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "ConfigParser.C"
#include <string>
void testRandomAccess(){
ConfigParser conf("test.conf");
cout<<"==================\n";
cout<<"Loading Configuration for Name=80"<<endl;
conf.loadConfig("80");
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=76"<<endl;
conf.loadConfig("76");
conf.print();
cout<<"==================\n\n";
cout<<"==================\n";
cout<<"Loading Configuration for Name=80_vtx"<<endl;
conf.loadConfig("80_vtx");
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=76"<<endl;
conf.loadConfig("76");
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=80_vtx_mf"<<endl;
conf.loadConfig("80_vtx_mf");
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=76"<<endl;
conf.loadConfig("76");
conf.print();
cout<<"==================\n\n";
cout<<"==================\n";
cout<<"Loading First Configuration"<<endl;
string name = conf.findFirstConfig();
cout<<"Config is named: "<<name<<endl;
if (name=="76"){
cout<<"Name is 76"<<endl;
}
else{
cout<<"Name is not 76"<<endl;
}
conf.loadConfig(name);
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=80_vtx_mf"<<endl;
conf.loadConfig("80_vtx_mf");
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=76"<<endl;
conf.loadConfig("76");
conf.print();
cout<<"==================\n\n";
cout<<"Loading Configuration for Name=NONE"<<endl;
conf.loadConfig("NONE"); //should throw error
conf.print();
cout<<"==================\n\n";
//No breaking after it can't find one
cout<<"Loading Configuration for Name=76"<<endl;
conf.loadConfig("76");
conf.print();
cout<<"==================\n\n";
}
void testSeqAccess(){
ConfigParser conf("test.conf");
while (conf.loadNextConfig()){
cout<<"CONFIG:"<<endl;
conf.print();
}
}
void testMemLeak(){
ConfigParser *conf = new ConfigParser("test.conf");
conf->loadNextConfig();
for (int i = 0; i<100000000; i++){
for (int j = 0; j<100; j++){
if (conf->get(to_string( double (i-(j/100.)) ) ) != ""){
cout<<"conf has "<<(double (i-(j/100.)))<<endl;
}
}
}
}
void testConfigReset(){
ConfigParser conf("test.conf");
conf.loadNextConfig();
conf.print();
conf.loadNextConfig();
conf.print();
conf.loadConfig("80");
conf.print();
conf.loadNextConfig();
conf.print();
}
int main(){
cout<<"Random Access Testing:"<<endl;
testRandomAccess();
cout<<"\n\nSequential Testing:"<<endl;
testSeqAccess();
cout<<"\n\nReset Testing:"<<endl;
testConfigReset();
cout<<"\n\n Testing Mem Leak:"<<endl;
testMemLeak();
}