aboutsummaryrefslogtreecommitdiff
path: root/src/tests/Resourcetest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/Resourcetest.cc')
-rw-r--r--src/tests/Resourcetest.cc106
1 files changed, 53 insertions, 53 deletions
diff --git a/src/tests/Resourcetest.cc b/src/tests/Resourcetest.cc
index 9379663..f82c4b4 100644
--- a/src/tests/Resourcetest.cc
+++ b/src/tests/Resourcetest.cc
@@ -41,35 +41,35 @@ enum TestEnum{TEST1, THIS_IS_TRUE, USE_LOVE};
41template<> 41template<>
42void Resource<TestEnum>:: 42void Resource<TestEnum>::
43setFromString(const char *str) { 43setFromString(const char *str) {
44 if (strcasecmp(str, "TEST1")==0) 44 if (strcasecmp(str, "TEST1")==0)
45 *this = TEST1; 45 *this = TEST1;
46 else if (strcasecmp(str, "THIS_IS_TRUE")==0) 46 else if (strcasecmp(str, "THIS_IS_TRUE")==0)
47 *this = THIS_IS_TRUE; 47 *this = THIS_IS_TRUE;
48 else if (strcasecmp(str, "USE_LOVE")==0) 48 else if (strcasecmp(str, "USE_LOVE")==0)
49 *this = USE_LOVE; 49 *this = USE_LOVE;
50} 50}
51 51
52template<> 52template<>
53void Resource<int>:: 53void Resource<int>::
54setFromString(const char* strval) { 54setFromString(const char* strval) {
55 int val; 55 int val;
56 if (sscanf(strval, "%d", &val)==1) 56 if (sscanf(strval, "%d", &val)==1)
57 *this = val; 57 *this = val;
58} 58}
59 59
60template<> 60template<>
61void Resource<std::string>:: 61void Resource<std::string>::
62setFromString(const char *strval) { 62setFromString(const char *strval) {
63 *this = strval; 63 *this = strval;
64} 64}
65 65
66template<> 66template<>
67void Resource<bool>:: 67void Resource<bool>::
68setFromString(char const *strval) { 68setFromString(char const *strval) {
69 if (strcasecmp(strval, "true")==0) 69 if (strcasecmp(strval, "true")==0)
70 *this = true; 70 *this = true;
71 else 71 else
72 *this = false; 72 *this = false;
73} 73}
74 74
75//----------------- 75//-----------------
@@ -78,29 +78,29 @@ setFromString(char const *strval) {
78template<> 78template<>
79std::string Resource<TestEnum>:: 79std::string Resource<TestEnum>::
80getString() { 80getString() {
81 switch (m_value) { 81 switch (m_value) {
82 case TEST1: 82 case TEST1:
83 return string("TEST1"); 83 return string("TEST1");
84 case THIS_IS_TRUE: 84 case THIS_IS_TRUE:
85 return string("THIS_IS_TRUE"); 85 return string("THIS_IS_TRUE");
86 case USE_LOVE: 86 case USE_LOVE:
87 return string("USE_LOVE"); 87 return string("USE_LOVE");
88 } 88 }
89 return string(""); 89 return string("");
90} 90}
91 91
92template<> 92template<>
93std::string Resource<bool>:: 93std::string Resource<bool>::
94getString() { 94getString() {
95 return std::string(**this == true ? "true" : "false"); 95 return std::string(**this == true ? "true" : "false");
96} 96}
97 97
98template<> 98template<>
99std::string Resource<int>:: 99std::string Resource<int>::
100getString() { 100getString() {
101 char strval[256]; 101 char strval[256];
102 sprintf(strval, "%d", **this); 102 sprintf(strval, "%d", **this);
103 return std::string(strval); 103 return std::string(strval);
104} 104}
105 105
106template<> 106template<>
@@ -109,32 +109,32 @@ getString() { return **this; }
109 109
110int main(int argc, char **argv) { 110int main(int argc, char **argv) {
111 111
112 ResourceManager rm; 112 ResourceManager rm;
113 // resources 113 // resources
114 Resource<int> val(rm, 123, "session.test", "Session.Test"); 114 Resource<int> val(rm, 123, "session.test", "Session.Test");
115 Resource<bool> boolval(rm, true, "session.bool", "Session.Bool"); 115 Resource<bool> boolval(rm, true, "session.bool", "Session.Bool");
116 Resource<string> strval(rm, "none", "string", "String"); 116 Resource<string> strval(rm, "none", "string", "String");
117 Resource<TestEnum> enumval(rm, TEST1, "enumval", "EnumVal"); 117 Resource<TestEnum> enumval(rm, TEST1, "enumval", "EnumVal");
118 118
119 const char *defaultfile_open = "res", 119 const char *defaultfile_open = "res",
120 *defaultfile_save = "res_save"; 120 *defaultfile_save = "res_save";
121 121
122 if (argc>1) { 122 if (argc>1) {
123 if(!rm.load(argv[1])) 123 if(!rm.load(argv[1]))
124 cerr<<"Faild to load database: "<<argv[1]<<endl; 124 cerr<<"Faild to load database: "<<argv[1]<<endl;
125 } else { 125 } else {
126 if (!rm.load(defaultfile_open)) 126 if (!rm.load(defaultfile_open))
127 cerr<<"Faild to load database: "<<defaultfile_open<<endl; 127 cerr<<"Faild to load database: "<<defaultfile_open<<endl;
128 } 128 }
129 cerr<<"Value="<<*val<<endl; 129 cerr<<"Value="<<*val<<endl;
130 cerr<<"boolValue="<<boolval.getString()<<endl; 130 cerr<<"boolValue="<<boolval.getString()<<endl;
131 cerr<<"strValue="<<*strval<<endl; 131 cerr<<"strValue="<<*strval<<endl;
132 cerr<<"enumValue="<<enumval.getString()<<endl; 132 cerr<<"enumValue="<<enumval.getString()<<endl;
133 133
134 if (!rm.save(defaultfile_save)) 134 if (!rm.save(defaultfile_save))
135 cerr<<"Faild to save database to file:"<<defaultfile_save<<endl; 135 cerr<<"Faild to save database to file:"<<defaultfile_save<<endl;
136 136
137 if (!rm.save("I dont exist", "Not me either")) 137 if (!rm.save("I dont exist", "Not me either"))
138 cerr<<"faild to save and merge database."<<endl; 138 cerr<<"faild to save and merge database."<<endl;
139 return 0; 139 return 0;
140} 140}