PageRenderTime 5ms CodeModel.GetById 34ms app.highlight 31ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/llmessage/tests/llpartdata_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 216 lines | 139 code | 49 blank | 28 comment | 11 complexity | 114419a03dd6295618a0bba10b65bce9 MD5 | raw file
  1/**
  2 * @file llpartdata_tut.cpp
  3 * @author Adroit
  4 * @date March 2007
  5 * @brief LLPartData and LLPartSysData test cases.
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "lldatapacker.h"
 31#include "v3math.h"
 32#include "llsdserialize.h"
 33#include "message.h"
 34
 35#include "../llpartdata.h"
 36
 37#include "../test/lltut.h"
 38
 39namespace tut
 40{
 41	
 42	struct partdata_test
 43	{
 44	};
 45	typedef test_group<partdata_test> partdata_test_t;
 46	typedef partdata_test_t::object partdata_test_object_t;
 47	tut::partdata_test_t tut_partdata_test("LLPartData");
 48
 49	template<> template<>
 50	void partdata_test_object_t::test<1>()
 51	{
 52		LLPartData llpdata,llpdata1;
 53		U8 pkbuf[128];
 54
 55		llpdata.setFlags(LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK |
 56		LLPartData::LL_PART_BOUNCE_MASK | LLPartData::LL_PART_WIND_MASK | LLPartData::LL_PART_FOLLOW_SRC_MASK |
 57		LLPartData::LL_PART_FOLLOW_VELOCITY_MASK | LLPartData::LL_PART_TARGET_POS_MASK | LLPartData::LL_PART_TARGET_LINEAR_MASK |
 58		LLPartData::LL_PART_EMISSIVE_MASK | LLPartData::LL_PART_BEAM_MASK | LLPartData::LL_PART_DEAD_MASK);
 59
 60		llpdata.setMaxAge(29.3f);
 61
 62		LLVector3 llvec1(1.0f, .5f, .25f);
 63		llpdata.setStartColor(llvec1);
 64		llpdata.setStartAlpha(.7f);
 65
 66		LLVector3 llvec2(.2f, .3f, 1.0f);
 67		llpdata.setEndColor(llvec2);
 68		llpdata.setEndAlpha(1.0f);
 69
 70		llpdata.setStartScale(3.23f, 4.0f);
 71		llpdata.setEndScale(2.4678f, 1.0f);
 72
 73		LLDataPackerBinaryBuffer dp((U8*)pkbuf, 128);
 74		llpdata.pack(dp);
 75		
 76		S32 cur_size = dp.getCurrentSize();
 77		
 78		LLDataPackerBinaryBuffer dp1((U8*)pkbuf, cur_size);
 79		llpdata1.unpack(dp1);
 80
 81		ensure("1.mFlags values are different after unpacking", llpdata1.mFlags == llpdata.mFlags);
 82		ensure_approximately_equals("2.mMaxAge values are different after unpacking", llpdata1.mMaxAge, llpdata.mMaxAge, 8);
 83
 84		ensure_approximately_equals("3.mStartColor[0] values are different after unpacking", llpdata1.mStartColor.mV[0], llpdata.mStartColor.mV[0], 8);
 85		ensure_approximately_equals("4.mStartColor[1] values are different after unpacking", llpdata1.mStartColor.mV[1], llpdata.mStartColor.mV[1], 8);
 86		ensure_approximately_equals("5.mStartColor[2] values are different after unpacking", llpdata1.mStartColor.mV[2], llpdata.mStartColor.mV[2], 8);
 87		ensure_approximately_equals("6.mStartColor[3] values are different after unpacking", llpdata1.mStartColor.mV[3], llpdata.mStartColor.mV[3], 8);
 88
 89		ensure_approximately_equals("7.mEndColor[0] values are different after unpacking", llpdata1.mEndColor.mV[0], llpdata.mEndColor.mV[0], 8);
 90		ensure_approximately_equals("8.mEndColor[1] values are different after unpacking", llpdata1.mEndColor.mV[1], llpdata.mEndColor.mV[1], 8);
 91		ensure_approximately_equals("9.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[2], llpdata.mEndColor.mV[2], 8);
 92		ensure_approximately_equals("10.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[3], llpdata.mEndColor.mV[3], 8);
 93
 94		ensure_approximately_equals("11.mStartScale[0] values are different after unpacking", llpdata1.mStartScale.mV[0], llpdata.mStartScale.mV[0], 5);
 95		ensure_approximately_equals("12.mStartScale[1] values are different after unpacking", llpdata1.mStartScale.mV[1], llpdata.mStartScale.mV[1], 5);
 96
 97		ensure_approximately_equals("13.mEndScale[0] values are different after unpacking", llpdata1.mEndScale.mV[0], llpdata.mEndScale.mV[0], 5);
 98		ensure_approximately_equals("14.mEndScale[1] values are different after unpacking", llpdata1.mEndScale.mV[1], llpdata.mEndScale.mV[1], 5);
 99	}
100
101
102	template<> template<>
103	void partdata_test_object_t::test<2>()
104	{
105		LLPartData llpdata,llpdata1;
106
107		llpdata.setFlags(LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK |
108		LLPartData::LL_PART_BOUNCE_MASK | LLPartData::LL_PART_WIND_MASK | LLPartData::LL_PART_FOLLOW_SRC_MASK |
109		LLPartData::LL_PART_FOLLOW_VELOCITY_MASK | LLPartData::LL_PART_TARGET_POS_MASK | LLPartData::LL_PART_TARGET_LINEAR_MASK |
110		LLPartData::LL_PART_EMISSIVE_MASK | LLPartData::LL_PART_BEAM_MASK | LLPartData::LL_PART_DEAD_MASK);
111		
112		llpdata.setMaxAge(29.3f);
113
114		LLVector3 llvec1(1.0f, .5f, .25f);
115		llpdata.setStartColor(llvec1);
116		llpdata.setStartAlpha(.7f);
117
118		LLVector3 llvec2(.2f, .3f, 1.0f);
119		llpdata.setEndColor(llvec2);
120		llpdata.setEndAlpha(1.0f);
121
122		llpdata.setStartScale(3.23f, 4.0f);
123		llpdata.setEndScale(2.4678f, 1.0f);
124
125		LLSD llsd = llpdata.asLLSD();
126
127		llpdata1.fromLLSD(llsd);
128
129		ensure("1.mFlags values are different after unpacking", llpdata1.mFlags == llpdata.mFlags);
130		ensure_approximately_equals("2.mMaxAge values are different after unpacking", llpdata1.mMaxAge, llpdata.mMaxAge, 8);
131
132		ensure_approximately_equals("3.mStartColor[0] values are different after unpacking", llpdata1.mStartColor.mV[0], llpdata.mStartColor.mV[0], 8);
133		ensure_approximately_equals("4.mStartColor[1] values are different after unpacking", llpdata1.mStartColor.mV[1], llpdata.mStartColor.mV[1], 8);
134		ensure_approximately_equals("5.mStartColor[2] values are different after unpacking", llpdata1.mStartColor.mV[2], llpdata.mStartColor.mV[2], 8);
135		ensure_approximately_equals("6.mStartColor[3] values are different after unpacking", llpdata1.mStartColor.mV[3], llpdata.mStartColor.mV[3], 8);
136
137		ensure_approximately_equals("7.mEndColor[0] values are different after unpacking", llpdata1.mEndColor.mV[0], llpdata.mEndColor.mV[0], 8);
138		ensure_approximately_equals("8.mEndColor[1] values are different after unpacking", llpdata1.mEndColor.mV[1], llpdata.mEndColor.mV[1], 8);
139		ensure_approximately_equals("9.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[2], llpdata.mEndColor.mV[2], 8);
140		ensure_approximately_equals("10.mEndColor[2] values are different after unpacking", llpdata1.mEndColor.mV[3], llpdata.mEndColor.mV[3], 8);
141
142		ensure_approximately_equals("11.mStartScale[0] values are different after unpacking", llpdata1.mStartScale.mV[0], llpdata.mStartScale.mV[0], 5);
143		ensure_approximately_equals("12.mStartScale[1] values are different after unpacking", llpdata1.mStartScale.mV[1], llpdata.mStartScale.mV[1], 5);
144
145		ensure_approximately_equals("13.mEndScale[0] values are different after unpacking", llpdata1.mEndScale.mV[0], llpdata.mEndScale.mV[0], 5);
146		ensure_approximately_equals("14.mEndScale[1] values are different after unpacking", llpdata1.mEndScale.mV[1], llpdata.mEndScale.mV[1], 5);
147	}
148
149
150//*********llpartsysdata***********
151
152	template<> template<>
153	void partdata_test_object_t::test<3>()
154	{
155		LLPartSysData llpsysdata, llpsysdata1;
156		U8 pkbuf[256];
157		llpsysdata.setBurstSpeedMin(33.33f);
158		ensure("1.mBurstSpeedMin coudnt be set", 33.33f == llpsysdata.mBurstSpeedMin);
159
160		llpsysdata.setBurstSpeedMax(44.44f); 
161		ensure("2.mBurstSpeedMax coudnt be set", 44.44f == llpsysdata.mBurstSpeedMax);
162
163		llpsysdata.setBurstRadius(45.55f);
164		ensure("3.mBurstRadius coudnt be set", 45.55f == llpsysdata.mBurstRadius);
165
166		LLVector3 llvec(44.44f, 111.11f, -40.4f);
167		llpsysdata.setPartAccel(llvec);
168
169		llpsysdata.mCRC = 0xFFFFFFFF;
170		llpsysdata.mFlags = 0x20;
171
172		llpsysdata.mPattern = LLPartSysData::LL_PART_SRC_PATTERN_ANGLE_CONE_EMPTY;
173
174		llpsysdata.mMaxAge = 99.99f;
175		llpsysdata.mStartAge = 18.5f;
176		llpsysdata.mInnerAngle = 4.234f;
177		llpsysdata.mOuterAngle = 7.123f;
178		llpsysdata.mBurstRate  = 245.53f;
179		llpsysdata.mBurstPartCount = 0xFF;
180		llpsysdata.mAngularVelocity = llvec;
181
182		llpsysdata.mPartImageID.generate();
183		llpsysdata.mTargetUUID.generate();
184		
185		LLDataPackerBinaryBuffer dp((U8*)pkbuf, 256);
186		llpsysdata.pack(dp);
187		S32 cur_size = dp.getCurrentSize();
188		LLDataPackerBinaryBuffer dp1((U8*)pkbuf, cur_size);
189		llpsysdata1.unpack(dp1);
190
191		ensure("1.mCRC's not equal", llpsysdata.mCRC == llpsysdata1.mCRC);
192		ensure("2.mFlags's not equal", llpsysdata.mFlags == llpsysdata1.mFlags);
193		ensure("3.mPattern's not equal", llpsysdata.mPattern == llpsysdata1.mPattern);
194		ensure_approximately_equals("4.mMaxAge's not equal", llpsysdata.mMaxAge , llpsysdata1.mMaxAge, 8);
195		ensure_approximately_equals("5.mStartAge's not equal", llpsysdata.mStartAge, llpsysdata1.mStartAge, 8);
196		ensure_approximately_equals("6.mOuterAngle's not equal", llpsysdata.mOuterAngle, llpsysdata1.mOuterAngle, 5);
197		ensure_approximately_equals("7.mInnerAngles's not equal", llpsysdata.mInnerAngle, llpsysdata1.mInnerAngle, 5);
198		ensure_approximately_equals("8.mBurstRate's not equal", llpsysdata.mBurstRate, llpsysdata1.mBurstRate, 8);
199		ensure("9.mBurstPartCount's not equal", llpsysdata.mBurstPartCount == llpsysdata1.mBurstPartCount);
200
201		ensure_approximately_equals("10.mBurstSpeedMin's not equal", llpsysdata.mBurstSpeedMin, llpsysdata1.mBurstSpeedMin, 8);
202		ensure_approximately_equals("11.mBurstSpeedMax's not equal", llpsysdata.mBurstSpeedMax, llpsysdata1.mBurstSpeedMax, 8);
203
204		ensure_approximately_equals("12.mAngularVelocity's not equal", llpsysdata.mAngularVelocity.mV[0], llpsysdata1.mAngularVelocity.mV[0], 7);
205		ensure_approximately_equals("13.mAngularVelocity's not equal", llpsysdata.mAngularVelocity.mV[1], llpsysdata1.mAngularVelocity.mV[1], 7);
206		ensure_approximately_equals("14.mAngularVelocity's not equal", llpsysdata.mAngularVelocity.mV[2], llpsysdata1.mAngularVelocity.mV[2], 7);
207			
208		ensure_approximately_equals("15.mPartAccel's not equal", llpsysdata.mPartAccel.mV[0], llpsysdata1.mPartAccel.mV[0], 7);
209		ensure_approximately_equals("16.mPartAccel's not equal", llpsysdata.mPartAccel.mV[1], llpsysdata1.mPartAccel.mV[1], 7);
210		ensure_approximately_equals("17.mPartAccel's not equal", llpsysdata.mPartAccel.mV[2], llpsysdata1.mPartAccel.mV[2], 7);
211
212		ensure("18.mPartImageID's not equal", llpsysdata.mPartImageID == llpsysdata1.mPartImageID);
213		ensure("19.mTargetUUID's not equal", llpsysdata.mTargetUUID == llpsysdata1.mTargetUUID);
214		ensure_approximately_equals("20.mBurstRadius's not equal", llpsysdata.mBurstRadius, llpsysdata1.mBurstRadius, 8);
215	}
216}