v4coloru_tut.cpp

Go to the documentation of this file.
00001 
00035 #include <tut/tut.h>
00036 #include "linden_common.h"
00037 #include "lltut.h"
00038 #include "llsd.h"
00039 #include "v4coloru.h"
00040 
00041 
00042 namespace tut
00043 {
00044         struct v4coloru_data
00045         {
00046         };
00047         typedef test_group<v4coloru_data> v4coloru_test;
00048         typedef v4coloru_test::object v4coloru_object;
00049         tut::v4coloru_test v4coloru_testcase("v4coloru");
00050 
00051         template<> template<>
00052         void v4coloru_object::test<1>()
00053         {
00054                 LLColor4U llcolor4u;
00055                 ensure("1:LLColor4u:Fail to initialize ", ((0 == llcolor4u.mV[VX]) && (0 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW])));
00056 
00057                 U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23;
00058                 LLColor4U llcolor4u1(r,g,b);
00059                 ensure("2:LLColor4u:Fail to initialize ", ((r == llcolor4u1.mV[VX]) && (g == llcolor4u1.mV[VY]) && (b == llcolor4u1.mV[VZ])&& (255 == llcolor4u1.mV[VW])));
00060                 
00061                 LLColor4U llcolor4u2(r,g,b,a);
00062                 ensure("3:LLColor4u:Fail to initialize ", ((r == llcolor4u2.mV[VX]) && (g == llcolor4u2.mV[VY]) && (b == llcolor4u2.mV[VZ])&& (a == llcolor4u2.mV[VW])));
00063 
00064                 const U8 vec[4] = {0x12,0xFF,0xAF,0x23};
00065                 LLColor4U llcolor4u3(vec);
00066                 ensure("4:LLColor4u:Fail to initialize ", ((vec[0] == llcolor4u3.mV[VX]) && (vec[1] == llcolor4u3.mV[VY]) && (vec[2] == llcolor4u3.mV[VZ])&& (vec[3] == llcolor4u3.mV[VW])));           
00067 
00068                 LLSD sd = llcolor4u3.getValue();
00069                 LLColor4U llcolor4u4(sd);
00070                 ensure_equals("5:LLColor4u (LLSD) Failed ", llcolor4u4, llcolor4u3);
00071         }
00072         
00073         template<> template<>
00074         void v4coloru_object::test<2>()
00075         {
00076                 LLColor4U llcolor4ua(1, 2, 3, 4);
00077                 LLSD sd = llcolor4ua.getValue();
00078                 LLColor4U llcolor4u;
00079                 llcolor4u.setValue(sd);
00080                 ensure_equals("setValue(LLSD)/getValue Failed ", llcolor4u, llcolor4ua);
00081         }
00082 
00083         template<> template<>
00084         void v4coloru_object::test<3>()
00085         {
00086                 U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23;
00087                 LLColor4U llcolor4u(r,g,b,a);
00088                 llcolor4u.setToBlack();
00089                 ensure("setToBlack:Fail to set black ", ((0 == llcolor4u.mV[VX]) && (0 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW])));
00090 
00091                 llcolor4u.setToWhite();
00092                 ensure("setToWhite:Fail to white ", ((255 == llcolor4u.mV[VX]) && (255 == llcolor4u.mV[VY]) && (255 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW])));
00093         }
00094         
00095         template<> template<>
00096         void v4coloru_object::test<4>()
00097         {
00098                 U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23;
00099                 LLColor4U llcolor4ua(r,g,b,a);
00100                 LLSD sd = llcolor4ua.getValue();
00101                 LLColor4U llcolor4u = sd;
00102                 ensure_equals("Operator=(LLSD) Failed ",  llcolor4u, llcolor4ua);
00103         }
00104 
00105         template<> template<>
00106         void v4coloru_object::test<5>()
00107         {
00108                 U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23;
00109                 LLColor4U llcolor4u;
00110                 llcolor4u.setVec(r,g,b,a);
00111                 ensure("1:setVec:Fail to set the values ", ((r == llcolor4u.mV[VX]) && (g == llcolor4u.mV[VY]) && (b == llcolor4u.mV[VZ])&& (a == llcolor4u.mV[VW])));
00112 
00113                 llcolor4u.setToBlack();
00114                 llcolor4u.setVec(r,g,b);
00115                 ensure("2:setVec:Fail to set the values ", ((r == llcolor4u.mV[VX]) && (g == llcolor4u.mV[VY]) && (b == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW])));
00116 
00117                 LLColor4U llcolor4u1;
00118                 llcolor4u1.setVec(llcolor4u);
00119                 ensure_equals("3:setVec:Fail to set the values ", llcolor4u1,llcolor4u);
00120                 
00121                 const U8 vec[4] = {0x12,0xFF,0xAF,0x23};
00122                 LLColor4U llcolor4u2;
00123                 llcolor4u2.setVec(vec);
00124                 ensure("4:setVec:Fail to set the values ", ((vec[0] == llcolor4u2.mV[VX]) && (vec[1] == llcolor4u2.mV[VY]) && (vec[2] == llcolor4u2.mV[VZ])&& (vec[3] == llcolor4u2.mV[VW])));          
00125         }
00126         
00127         template<> template<>
00128         void v4coloru_object::test<6>()
00129         {
00130                 U8 alpha = 0x12;
00131                 LLColor4U llcolor4u;
00132                 llcolor4u.setAlpha(alpha);
00133                 ensure("setAlpha:Fail to set alpha value ", (alpha == llcolor4u.mV[VW]));
00134         }
00135         
00136         template<> template<>
00137         void v4coloru_object::test<7>()
00138         {
00139                 U8 r = 0x12, g = 0xFF, b = 0xAF;
00140                 LLColor4U llcolor4u(r,g,b);
00141                 ensure("magVecSquared:Fail ", is_approx_equal(llcolor4u.magVecSquared(), (F32)(r*r + g*g + b*b)));
00142                 ensure("magVec:Fail ", is_approx_equal(llcolor4u.magVec(), fsqrtf(r*r + g*g + b*b)));
00143         }
00144 
00145         template<> template<>
00146         void v4coloru_object::test<8>()
00147         {
00148                 U8 r = 0x12, g = 0xFF, b = 0xAF;
00149                 std::ostringstream stream1, stream2;
00150                 LLColor4U llcolor4u1(r,g,b),llcolor4u2;
00151                 stream1 << llcolor4u1;
00152                 llcolor4u2.setVec(r,g,b);
00153                 stream2 << llcolor4u2;
00154                 ensure("operator << failed ", (stream1.str() == stream2.str()));        
00155         }
00156 
00157         template<> template<>
00158         void v4coloru_object::test<9>()
00159         {
00160                 U8 r1 = 0x12, g1 = 0xFF, b1 = 0xAF;
00161                 U8 r2 = 0x1C, g2 = 0x9A, b2 = 0x1B;
00162                 LLColor4U llcolor4u1(r1,g1,b1), llcolor4u2(r2,g2,b2),llcolor4u3;
00163                 llcolor4u3 = llcolor4u1 + llcolor4u2;
00164                 ensure_equals(
00165                         "1a.operator+:Fail to Add the values ",
00166                         llcolor4u3.mV[VX],
00167                         (U8)(r1+r2));
00168                 ensure_equals(
00169                         "1b.operator+:Fail to Add the values ",
00170                         llcolor4u3.mV[VY],
00171                         (U8)(g1+g2));
00172                 ensure_equals(
00173                         "1c.operator+:Fail to Add the values ",
00174                         llcolor4u3.mV[VZ],
00175                         (U8)(b1+b2));
00176 
00177                 llcolor4u2 += llcolor4u1;
00178                 ensure_equals(
00179                         "2a.operator+=:Fail to Add the values ",
00180                         llcolor4u2.mV[VX],
00181                         (U8)(r1+r2));
00182                 ensure_equals(
00183                         "2b.operator+=:Fail to Add the values ",
00184                         llcolor4u2.mV[VY],
00185                         (U8)(g1+g2));
00186                 ensure_equals(
00187                         "2c.operator+=:Fail to Add the values ",
00188                         llcolor4u2.mV[VZ],
00189                         (U8)(b1+b2));
00190         }
00191 
00192         template<> template<>
00193         void v4coloru_object::test<10>()
00194         {
00195                 U8 r1 = 0x12, g1 = 0xFF, b1 = 0xAF;
00196                 U8 r2 = 0x1C, g2 = 0x9A, b2 = 0x1B;
00197                 LLColor4U llcolor4u1(r1,g1,b1), llcolor4u2(r2,g2,b2),llcolor4u3;
00198                 llcolor4u3 = llcolor4u1 - llcolor4u2;
00199                 ensure_equals(
00200                         "1a. operator-:Fail to Add the values ",
00201                         llcolor4u3.mV[VX],
00202                         (U8)(r1-r2));
00203                 ensure_equals(
00204                         "1b. operator-:Fail to Add the values ",
00205                         llcolor4u3.mV[VY],
00206                         (U8)(g1-g2));
00207                 ensure_equals(
00208                         "1c. operator-:Fail to Add the values ",
00209                         llcolor4u3.mV[VZ],
00210                         (U8)(b1-b2));
00211 
00212                 llcolor4u1 -= llcolor4u2;
00213                 ensure_equals(
00214                         "2a. operator-=:Fail to Add the values ",
00215                         llcolor4u1.mV[VX],
00216                         (U8)(r1-r2));
00217                 ensure_equals(
00218                         "2b. operator-=:Fail to Add the values ",
00219                         llcolor4u1.mV[VY],
00220                         (U8)(g1-g2));
00221                 ensure_equals(
00222                         "2c. operator-=:Fail to Add the values ",
00223                         llcolor4u1.mV[VZ],
00224                         (U8)(b1-b2));
00225         }
00226 
00227         template<> template<>
00228         void v4coloru_object::test<11>()
00229         {
00230                 U8 r1 = 0x12, g1 = 0xFF, b1 = 0xAF;
00231                 U8 r2 = 0x1C, g2 = 0x9A, b2 = 0x1B;
00232                 LLColor4U llcolor4u1(r1,g1,b1), llcolor4u2(r2,g2,b2),llcolor4u3;
00233                 llcolor4u3 = llcolor4u1 * llcolor4u2;
00234                 ensure_equals(
00235                         "1a. operator*:Fail to multiply the values",
00236                         llcolor4u3.mV[VX],
00237                         (U8)(r1*r2));
00238                 ensure_equals(
00239                         "1b. operator*:Fail to multiply the values",
00240                         llcolor4u3.mV[VY],
00241                         (U8)(g1*g2));
00242                 ensure_equals(
00243                         "1c. operator*:Fail to multiply the values",
00244                         llcolor4u3.mV[VZ],
00245                         (U8)(b1*b2));
00246                 
00247                 U8 mulVal = 123;
00248                 llcolor4u1 *= mulVal;
00249                 ensure_equals(
00250                         "2a. operator*=:Fail to multiply the values",
00251                         llcolor4u1.mV[VX],
00252                         (U8)(r1*mulVal));
00253                 ensure_equals(
00254                         "2b. operator*=:Fail to multiply the values",
00255                         llcolor4u1.mV[VY],
00256                         (U8)(g1*mulVal));
00257                 ensure_equals(
00258                         "2c. operator*=:Fail to multiply the values",
00259                         llcolor4u1.mV[VZ],
00260                         (U8)(b1*mulVal));
00261         }
00262 
00263         template<> template<>
00264         void v4coloru_object::test<12>()
00265         {
00266                 U8 r = 0x12, g = 0xFF, b = 0xAF;
00267                 LLColor4U llcolor4u(r,g,b),llcolor4u1;
00268                 llcolor4u1 = llcolor4u;
00269                 ensure("operator== failed to ensure the equality ", (llcolor4u1 == llcolor4u)); 
00270                 llcolor4u1.setToBlack();
00271                 ensure("operator!= failed to ensure the equality ", (llcolor4u1 != llcolor4u)); 
00272         }
00273 
00274         template<> template<>
00275         void v4coloru_object::test<13>()
00276         {
00277                 U8 r = 0x12, g = 0xFF, b = 0xAF, a = 12;
00278                 LLColor4U llcolor4u(r,g,b,a);
00279                 U8 modVal = 45;
00280                 llcolor4u %= modVal;
00281                 ensure_equals("operator%=:Fail ", llcolor4u.mV[VW], (U8)(a * modVal));
00282         }
00283 
00284         template<> template<>
00285         void v4coloru_object::test<14>()
00286         {
00287                 U8 r = 0x12, g = 0xFF, b = 0xAF, a = 12;
00288                 LLColor4U llcolor4u1(r,g,b,a);
00289                 const char *color = "12, 23, 132, 50";
00290                 LLColor4U::parseColor4U(color, &llcolor4u1);
00291                 ensure("parseColor4U() failed to parse the color value ", ((12 == llcolor4u1.mV[VX]) && (23 == llcolor4u1.mV[VY]) && (132 == llcolor4u1.mV[VZ])&& (50 == llcolor4u1.mV[VW])));
00292 
00293                 color = "12, 23, 132";
00294                 ensure("2:parseColor4U() failed to parse the color value ",  (FALSE == LLColor4U::parseColor4U(color, &llcolor4u1)));
00295 
00296                 color = "12";
00297                 ensure("2:parseColor4U() failed to parse the color value ",  (FALSE == LLColor4U::parseColor4U(color, &llcolor4u1)));
00298         }
00299 
00300         template<> template<>
00301         void v4coloru_object::test<15>()
00302         {
00303                 U8 r = 12, g = 123, b = 3, a = 2;
00304                 LLColor4U llcolor4u(r,g,b,a),llcolor4u1;
00305                 const F32 fVal = 3.f;
00306                 llcolor4u1 = llcolor4u.multAll(fVal);
00307                 ensure("multAll:Fail to multiply ", (((U8)llround(r * fVal) == llcolor4u1.mV[VX]) && (U8)llround(g * fVal) == llcolor4u1.mV[VY]
00308                                                                                         && ((U8)llround(b * fVal) == llcolor4u1.mV[VZ])&& ((U8)llround(a * fVal) == llcolor4u1.mV[VW])));               
00309         }
00310 
00311         template<> template<>
00312         void v4coloru_object::test<16>()
00313         {
00314                 U8 r1 = 12, g1 = 123, b1 = 3, a1 = 2;
00315                 U8 r2 = 23, g2 = 230, b2 = 124, a2 = 255;
00316                 LLColor4U llcolor4u(r1,g1,b1,a1),llcolor4u1(r2,g2,b2,a2);
00317                 llcolor4u1 = llcolor4u1.addClampMax(llcolor4u);
00318                 ensure("1:addClampMax():Fail to add the value ",  ((r1+r2 == llcolor4u1.mV[VX]) && (255 == llcolor4u1.mV[VY]) && (b1+b2 == llcolor4u1.mV[VZ])&& (255 == llcolor4u1.mV[VW])));
00319 
00320                 r1 = 132, g1 = 3, b1 = 3, a1 = 2;
00321                 r2 = 123, g2 = 230, b2 = 154, a2 = 25;
00322                 LLColor4U llcolor4u2(r1,g1,b1,a1),llcolor4u3(r2,g2,b2,a2);
00323                 llcolor4u3 = llcolor4u3.addClampMax(llcolor4u2);
00324                 ensure("2:addClampMax():Fail to add the value ",  ((255 == llcolor4u3.mV[VX]) && (g1+g2 == llcolor4u3.mV[VY]) && (b1+b2 == llcolor4u3.mV[VZ])&& (a1+a2 == llcolor4u3.mV[VW])));
00325         }
00326 
00327         template<> template<>
00328         void v4coloru_object::test<17>()
00329         {
00330                 F32 r = 23.f, g = 12.32f, b = -12.3f;
00331                 LLColor3 color3(r,g,b);
00332                 LLColor4U llcolor4u;
00333                 llcolor4u.setVecScaleClamp(color3);
00334                 const S32 MAX_COLOR = 255;
00335                 F32 color_scale_factor = MAX_COLOR/r;
00336                 S32 r2 = llround(r * color_scale_factor);
00337                 S32 g2 = llround(g * color_scale_factor);
00338                 ensure("setVecScaleClamp():Fail to add the value ",  ((r2 == llcolor4u.mV[VX]) && (g2 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW])));
00339         }
00340 }

Generated on Thu Jul 1 06:10:01 2010 for Second Life Viewer by  doxygen 1.4.7