00001
00034 #include "linden_common.h"
00035 #include "lltut.h"
00036
00037 #include "llmath.h"
00038 #include "lluuid.h"
00039 #include "llcrc.h"
00040
00041 namespace tut
00042 {
00043 struct math_data
00044 {
00045 };
00046 typedef test_group<math_data> math_test;
00047 typedef math_test::object math_object;
00048 tut::math_test tm("basic_linden_math");
00049
00050 template<> template<>
00051 void math_object::test<1>()
00052 {
00053 S32 val = 89543;
00054 val = llabs(val);
00055 ensure("integer absolute value 1", (89543 == val));
00056 val = -500;
00057 val = llabs(val);
00058 ensure("integer absolute value 2", (500 == val));
00059 }
00060
00061 template<> template<>
00062 void math_object::test<2>()
00063 {
00064 F32 val = -2583.4f;
00065 val = llabs(val);
00066 ensure("float absolute value 1", (2583.4f == val));
00067 val = 430903.f;
00068 val = llabs(val);
00069 ensure("float absolute value 2", (430903.f == val));
00070 }
00071
00072 template<> template<>
00073 void math_object::test<3>()
00074 {
00075 F64 val = 387439393.987329839;
00076 val = llabs(val);
00077 ensure("double absolute value 1", (387439393.987329839 == val));
00078 val = -8937843.9394878;
00079 val = llabs(val);
00080 ensure("double absolute value 2", (8937843.9394878 == val));
00081 }
00082
00083 template<> template<>
00084 void math_object::test<4>()
00085 {
00086 F32 val = 430903.9f;
00087 S32 val1 = lltrunc(val);
00088 ensure("float truncate value 1", (430903 == val1));
00089 val = -2303.9f;
00090 val1 = lltrunc(val);
00091 ensure("float truncate value 2", (-2303 == val1));
00092 }
00093
00094 template<> template<>
00095 void math_object::test<5>()
00096 {
00097 F64 val = 387439393.987329839 ;
00098 S32 val1 = lltrunc(val);
00099 ensure("float truncate value 1", (387439393 == val1));
00100 val = -387439393.987329839;
00101 val1 = lltrunc(val);
00102 ensure("float truncate value 2", (-387439393 == val1));
00103 }
00104
00105 template<> template<>
00106 void math_object::test<6>()
00107 {
00108 F32 val = 430903.2f;
00109 S32 val1 = llfloor(val);
00110 ensure("float llfloor value 1", (430903 == val1));
00111 val = -430903.9f;
00112 val1 = llfloor(val);
00113 ensure("float llfloor value 2", (-430904 == val1));
00114 }
00115
00116 template<> template<>
00117 void math_object::test<7>()
00118 {
00119 F32 val = 430903.2f;
00120 S32 val1 = llceil(val);
00121 ensure("float llceil value 1", (430904 == val1));
00122 val = -430903.9f;
00123 val1 = llceil(val);
00124 ensure("float llceil value 2", (-430903 == val1));
00125 }
00126
00127 template<> template<>
00128 void math_object::test<8>()
00129 {
00130 F32 val = 430903.2f;
00131 S32 val1 = llround(val);
00132 ensure("float llround value 1", (430903 == val1));
00133 val = -430903.9f;
00134 val1 = llround(val);
00135 ensure("float llround value 2", (-430904 == val1));
00136 }
00137
00138 template<> template<>
00139 void math_object::test<9>()
00140 {
00141 F32 val = 430905.2654f, nearest = 100.f;
00142 val = llround(val, nearest);
00143 ensure("float llround value 1", (430900 == val));
00144 val = -430905.2654f, nearest = 10.f;
00145 val = llround(val, nearest);
00146 ensure("float llround value 1", (-430910 == val));
00147 }
00148
00149 template<> template<>
00150 void math_object::test<10>()
00151 {
00152 F64 val = 430905.2654, nearest = 100.0;
00153 val = llround(val, nearest);
00154 ensure("double llround value 1", (430900 == val));
00155 val = -430905.2654, nearest = 10.0;
00156 val = llround(val, nearest);
00157 ensure("double llround value 1", (-430910.00000 == val));
00158 }
00159
00160 template<> template<>
00161 void math_object::test<11>()
00162 {
00163 const F32 F_PI = 3.1415926535897932384626433832795f;
00164 F32 angle = 3506.f;
00165 angle = llsimple_angle(angle);
00166 ensure("llsimple_angle value 1", (angle <=F_PI && angle >= -F_PI));
00167 angle = -431.f;
00168 angle = llsimple_angle(angle);
00169 ensure("llsimple_angle value 1", (angle <=F_PI && angle >= -F_PI));
00170 }
00171 }
00172
00173 namespace tut
00174 {
00175 struct uuid_data
00176 {
00177 LLUUID id;
00178 };
00179 typedef test_group<uuid_data> uuid_test;
00180 typedef uuid_test::object uuid_object;
00181 tut::uuid_test tu("uuid");
00182
00183 template<> template<>
00184 void uuid_object::test<1>()
00185 {
00186 ensure("uuid null", id.isNull());
00187 id.generate();
00188 ensure("generate not null", id.notNull());
00189 id.setNull();
00190 ensure("set null", id.isNull());
00191 }
00192
00193 template<> template<>
00194 void uuid_object::test<2>()
00195 {
00196 id.generate();
00197 LLUUID a(id);
00198 ensure_equals("copy equal", id, a);
00199 a.generate();
00200 ensure_not_equals("generate not equal", id, a);
00201 a = id;
00202 ensure_equals("assignment equal", id, a);
00203 }
00204
00205 template<> template<>
00206 void uuid_object::test<3>()
00207 {
00208 id.generate();
00209 LLUUID copy(id);
00210 LLUUID mask;
00211 mask.generate();
00212 copy ^= mask;
00213 ensure_not_equals("mask not equal", id, copy);
00214 copy ^= mask;
00215 ensure_equals("mask back", id, copy);
00216 }
00217
00218 template<> template<>
00219 void uuid_object::test<4>()
00220 {
00221 id.generate();
00222 std::string id_str = id.asString();
00223 LLUUID copy(id_str.c_str());
00224 ensure_equals("string serialization", id, copy);
00225 }
00226
00227 }
00228
00229 namespace tut
00230 {
00231 struct crc_data
00232 {
00233 };
00234 typedef test_group<crc_data> crc_test;
00235 typedef crc_test::object crc_object;
00236 tut::crc_test tc("crc");
00237
00238 template<> template<>
00239 void crc_object::test<1>()
00240 {
00241
00242 const char TEST_BUFFER[] = "hello &#$)$&Nd0";
00243 LLCRC c1, c2;
00244 c1.update((U8*)TEST_BUFFER, sizeof(TEST_BUFFER) - 1);
00245 char* rh = (char*)TEST_BUFFER;
00246 while(*rh != '\0')
00247 {
00248 c2.update(*rh);
00249 ++rh;
00250 }
00251 ensure_equals("crc update 1", c1.getCRC(), c2.getCRC());
00252 }
00253
00254 template<> template<>
00255 void crc_object::test<2>()
00256 {
00257
00258 const char TEST_BUFFER1[] = "Split Buffer one $^%$%#@$";
00259 const char TEST_BUFFER2[] = "Split Buffer two )(8723#5dsds";
00260 LLCRC c1, c2;
00261 c1.update((U8*)TEST_BUFFER1, sizeof(TEST_BUFFER1) - 1);
00262 char* rh = (char*)TEST_BUFFER2;
00263 while(*rh != '\0')
00264 {
00265 c1.update(*rh);
00266 ++rh;
00267 }
00268
00269 rh = (char*)TEST_BUFFER1;
00270 while(*rh != '\0')
00271 {
00272 c2.update(*rh);
00273 ++rh;
00274 }
00275 c2.update((U8*)TEST_BUFFER2, sizeof(TEST_BUFFER2) - 1);
00276
00277 ensure_equals("crc update 2", c1.getCRC(), c2.getCRC());
00278 }
00279 }