00001
00033 #include <tut/tut.h>
00034
00035 #include "linden_common.h"
00036 #include "lltut.h"
00037 #include "llsdmessagebuilder.h"
00038 #include "llsdmessagereader.h"
00039 #include "llsdtraits.h"
00040 #include "llquaternion.h"
00041 #include "u64.h"
00042 #include "v3dmath.h"
00043 #include "v3math.h"
00044 #include "v4math.h"
00045
00046 namespace tut
00047 {
00048 struct LLSDMessageBuilderTestData {
00049 static LLSDMessageBuilder defaultBuilder()
00050 {
00051 LLSDMessageBuilder builder;
00052 builder.newMessage("name");
00053 builder.nextBlock("block");
00054 return builder;
00055 }
00056
00057 static LLSDMessageReader setReader(const LLSDMessageBuilder& builder)
00058 {
00059 LLSDMessageReader reader;
00060 reader.setMessage("name", builder.getMessage());
00061 return reader;
00062 }
00063 };
00064
00065 typedef test_group<LLSDMessageBuilderTestData> LLSDMessageBuilderTestGroup;
00066 typedef LLSDMessageBuilderTestGroup::object LLSDMessageBuilderTestObject;
00067 LLSDMessageBuilderTestGroup llsdMessageBuilderTestGroup("LLSDMessageBuilder");
00068
00069 template<> template<>
00070 void LLSDMessageBuilderTestObject::test<1>()
00071
00072 {
00073 LLSDMessageBuilder builder = defaultBuilder();
00074 LLSDMessageReader reader = setReader(builder);
00075 }
00076
00077 template<> template<>
00078 void LLSDMessageBuilderTestObject::test<2>()
00079
00080 {
00081 BOOL outValue, inValue = TRUE;
00082 LLSDMessageBuilder builder = defaultBuilder();
00083 builder.addBOOL("var", inValue);
00084 LLSDMessageReader reader = setReader(builder);
00085 reader.getBOOL("block", "var", outValue);
00086 ensure_equals("Ensure BOOL", inValue, outValue);
00087 }
00088
00089 template<> template<>
00090 void LLSDMessageBuilderTestObject::test<3>()
00091
00092 {
00093 U8 outValue, inValue = 2;
00094 LLSDMessageBuilder builder = defaultBuilder();
00095 builder.addU8("var", inValue);
00096 LLSDMessageReader reader = setReader(builder);
00097 reader.getU8("block", "var", outValue);
00098 ensure_equals("Ensure U8", inValue, outValue);
00099 }
00100
00101 template<> template<>
00102 void LLSDMessageBuilderTestObject::test<4>()
00103
00104 {
00105 S16 outValue, inValue = 90;
00106 LLSDMessageBuilder builder = defaultBuilder();
00107 builder.addS16("var", inValue);
00108 LLSDMessageReader reader = setReader(builder);
00109 reader.getS16("block", "var", outValue);
00110 ensure_equals("Ensure S16", inValue, outValue);
00111 }
00112
00113 template<> template<>
00114 void LLSDMessageBuilderTestObject::test<5>()
00115
00116 {
00117 U16 outValue, inValue = 3;
00118 LLSDMessageBuilder builder = defaultBuilder();
00119 builder.addU16("var", inValue);
00120 LLSDMessageReader reader = setReader(builder);
00121 reader.getU16("block", "var", outValue);
00122 ensure_equals("Ensure U16", inValue, outValue);
00123 }
00124
00125 template<> template<>
00126 void LLSDMessageBuilderTestObject::test<6>()
00127
00128 {
00129 S32 outValue, inValue = 44;
00130 LLSDMessageBuilder builder = defaultBuilder();
00131 builder.addS32("var", inValue);
00132 LLSDMessageReader reader = setReader(builder);
00133 reader.getS32("block", "var", outValue);
00134 ensure_equals("Ensure S32", inValue, outValue);
00135 }
00136
00137 template<> template<>
00138 void LLSDMessageBuilderTestObject::test<7>()
00139
00140 {
00141 F32 outValue, inValue = 121.44f;
00142 LLSDMessageBuilder builder = defaultBuilder();
00143 builder.addF32("var", inValue);
00144 LLSDMessageReader reader = setReader(builder);
00145 reader.getF32("block", "var", outValue);
00146 ensure_equals("Ensure F32", inValue, outValue);
00147 }
00148
00149 template<> template<>
00150 void LLSDMessageBuilderTestObject::test<8>()
00151
00152 {
00153 U32 outValue, inValue = 88;
00154 LLSDMessageBuilder builder = defaultBuilder();
00155 builder.addU32("var", inValue);
00156 LLSDMessageReader reader = setReader(builder);
00157 reader.getU32("block", "var", outValue);
00158 ensure_equals("Ensure U32", inValue, outValue);
00159 }
00160
00161 template<> template<>
00162 void LLSDMessageBuilderTestObject::test<9>()
00163
00164 {
00165 U64 outValue, inValue = 121;
00166 LLSDMessageBuilder builder = defaultBuilder();
00167 builder.addU64("var", inValue);
00168 LLSDMessageReader reader = setReader(builder);
00169 reader.getU64("block", "var", outValue);
00170 ensure_equals("Ensure U64", inValue, outValue);
00171 }
00172
00173 template<> template<>
00174 void LLSDMessageBuilderTestObject::test<10>()
00175
00176 {
00177 F64 outValue, inValue = 3232143.33;
00178 LLSDMessageBuilder builder = defaultBuilder();
00179 builder.addF64("var", inValue);
00180 LLSDMessageReader reader = setReader(builder);
00181 reader.getF64("block", "var", outValue);
00182 ensure_equals("Ensure F64", inValue, outValue);
00183 }
00184
00185 template<> template<>
00186 void LLSDMessageBuilderTestObject::test<11>()
00187
00188 {
00189 LLVector3 outValue, inValue = LLVector3(1,2,3);
00190 LLSDMessageBuilder builder = defaultBuilder();
00191 builder.addVector3("var", inValue);
00192 LLSDMessageReader reader = setReader(builder);
00193 reader.getVector3("block", "var", outValue);
00194 ensure_equals("Ensure Vector3", inValue, outValue);
00195 }
00196
00197 template<> template<>
00198 void LLSDMessageBuilderTestObject::test<12>()
00199
00200 {
00201 LLVector4 outValue, inValue = LLVector4(1,2,3,4);
00202 LLSDMessageBuilder builder = defaultBuilder();
00203 builder.addVector4("var", inValue);
00204 LLSDMessageReader reader = setReader(builder);
00205 reader.getVector4("block", "var", outValue);
00206 ensure_equals("Ensure Vector4", inValue, outValue);
00207 }
00208
00209 template<> template<>
00210 void LLSDMessageBuilderTestObject::test<13>()
00211
00212 {
00213 LLVector3d outValue, inValue = LLVector3d(1,2,3);
00214 LLSDMessageBuilder builder = defaultBuilder();
00215 builder.addVector3d("var", inValue);
00216 LLSDMessageReader reader = setReader(builder);
00217 reader.getVector3d("block", "var", outValue);
00218 ensure_equals("Ensure Vector3d", inValue, outValue);
00219 }
00220
00221 template<> template<>
00222 void LLSDMessageBuilderTestObject::test<14>()
00223
00224 {
00225 LLQuaternion outValue, inValue = LLQuaternion(1,2,3,4);
00226 LLSDMessageBuilder builder = defaultBuilder();
00227 builder.addQuat("var", inValue);
00228 LLSDMessageReader reader = setReader(builder);
00229 reader.getQuat("block", "var", outValue);
00230 ensure_equals("Ensure Quaternion", inValue, outValue);
00231 }
00232
00233 template<> template<>
00234 void LLSDMessageBuilderTestObject::test<15>()
00235
00236 {
00237 LLUUID outValue, inValue;
00238 inValue.generate();
00239 LLSDMessageBuilder builder = defaultBuilder();
00240 builder.addUUID("var", inValue);
00241 LLSDMessageReader reader = setReader(builder);
00242 reader.getUUID("block", "var", outValue);
00243 ensure_equals("Ensure UUID", inValue, outValue);
00244 }
00245
00246 template<> template<>
00247 void LLSDMessageBuilderTestObject::test<16>()
00248
00249 {
00250 U32 outValue, inValue = 12344556;
00251 LLSDMessageBuilder builder = defaultBuilder();
00252 builder.addIPAddr("var", inValue);
00253 LLSDMessageReader reader = setReader(builder);
00254 reader.getIPAddr("block", "var", outValue);
00255 ensure_equals("Ensure IPAddr", inValue, outValue);
00256 }
00257
00258 template<> template<>
00259 void LLSDMessageBuilderTestObject::test<17>()
00260
00261 {
00262 U16 outValue, inValue = 80;
00263 LLSDMessageBuilder builder = defaultBuilder();
00264 builder.addIPPort("var", inValue);
00265 LLSDMessageReader reader = setReader(builder);
00266 reader.getIPPort("block", "var", outValue);
00267 ensure_equals("Ensure IPPort", inValue, outValue);
00268 }
00269
00270 template<> template<>
00271 void LLSDMessageBuilderTestObject::test<18>()
00272 {
00273 std::string outValue, inValue = "testing";
00274 LLSDMessageBuilder builder = defaultBuilder();
00275 builder.addString("var", inValue.c_str());
00276 LLSDMessageReader reader = setReader(builder);
00277 char buffer[MAX_STRING];
00278 reader.getString("block", "var", MAX_STRING, buffer);
00279 outValue = buffer;
00280 ensure_equals("Ensure String", inValue, outValue);
00281 }
00282 }
00283