diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/test/llcontrol_tut.cpp | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/llcontrol_tut.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/linden/indra/test/llcontrol_tut.cpp b/linden/indra/test/llcontrol_tut.cpp new file mode 100644 index 0000000..aabe205 --- /dev/null +++ b/linden/indra/test/llcontrol_tut.cpp | |||
@@ -0,0 +1,147 @@ | |||
1 | /** | ||
2 | * @file llcontrol_tut.cpp | ||
3 | * @date February 2008 | ||
4 | * @brief control group unit tests | ||
5 | * | ||
6 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
7 | * | ||
8 | * Copyright (c) 2008, Linden Research, Inc. | ||
9 | * | ||
10 | * Second Life Viewer Source Code | ||
11 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
12 | * to you under the terms of the GNU General Public License, version 2.0 | ||
13 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
14 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
15 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
16 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
17 | * | ||
18 | * There are special exceptions to the terms and conditions of the GPL as | ||
19 | * it is applied to this Source Code. View the full text of the exception | ||
20 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
21 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | */ | ||
32 | |||
33 | #include "linden_common.h" | ||
34 | |||
35 | #include <tut/tut.h> | ||
36 | #include "lltut.h" | ||
37 | |||
38 | #include "llcontrol.h" | ||
39 | #include "llsdserialize.h" | ||
40 | |||
41 | namespace tut | ||
42 | { | ||
43 | |||
44 | struct control_group | ||
45 | { | ||
46 | LLControlGroup* mCG; | ||
47 | LLString mTestConfigDir; | ||
48 | LLString mTestConfigFile; | ||
49 | static bool mListenerFired; | ||
50 | control_group() | ||
51 | { | ||
52 | mCG = new LLControlGroup; | ||
53 | LLUUID random; | ||
54 | random.generate(); | ||
55 | // generate temp dir | ||
56 | std::ostringstream oStr; | ||
57 | oStr << "/tmp/llcontrol-test-" << random << "/"; | ||
58 | mTestConfigDir = oStr.str(); | ||
59 | mTestConfigFile = mTestConfigDir + "settings.xml"; | ||
60 | LLFile::mkdir(mTestConfigDir.c_str()); | ||
61 | LLSD config; | ||
62 | config["TestSetting"]["Comment"] = "Dummy setting used for testing"; | ||
63 | config["TestSetting"]["Persist"] = 1; | ||
64 | config["TestSetting"]["Type"] = "U32"; | ||
65 | config["TestSetting"]["Value"] = 12; | ||
66 | writeSettingsFile(config); | ||
67 | } | ||
68 | ~control_group() | ||
69 | { | ||
70 | //Remove test files | ||
71 | delete mCG; | ||
72 | } | ||
73 | void writeSettingsFile(const LLSD& config) | ||
74 | { | ||
75 | llofstream file(mTestConfigFile.c_str()); | ||
76 | if (file.is_open()) | ||
77 | { | ||
78 | LLSDSerialize::toPrettyXML(config, file); | ||
79 | } | ||
80 | file.close(); | ||
81 | } | ||
82 | static bool handleListenerTest(const LLSD& newvalue) | ||
83 | { | ||
84 | control_group::mListenerFired = true; | ||
85 | return true; | ||
86 | } | ||
87 | }; | ||
88 | |||
89 | bool control_group::mListenerFired = false; | ||
90 | |||
91 | typedef test_group<control_group> control_group_test; | ||
92 | typedef control_group_test::object control_group_t; | ||
93 | control_group_test tut_control_group("control_group"); | ||
94 | |||
95 | //load settings from files - LLSD | ||
96 | template<> template<> | ||
97 | void control_group_t::test<1>() | ||
98 | { | ||
99 | int results = mCG->loadFromFile(mTestConfigFile.c_str()); | ||
100 | ensure("number of settings", (results == 1)); | ||
101 | ensure("value of setting", (mCG->getU32("TestSetting") == 12)); | ||
102 | } | ||
103 | |||
104 | //save settings to files | ||
105 | template<> template<> | ||
106 | void control_group_t::test<2>() | ||
107 | { | ||
108 | int results = mCG->loadFromFile(mTestConfigFile.c_str()); | ||
109 | mCG->setU32("TestSetting", 13); | ||
110 | ensure_equals("value of changed setting", mCG->getU32("TestSetting"), 13); | ||
111 | LLControlGroup test_cg; | ||
112 | LLString temp_test_file = (mTestConfigDir + "setting_llsd_temp.xml"); | ||
113 | mCG->saveToFile(temp_test_file.c_str(), TRUE); | ||
114 | results = test_cg.loadFromFile(temp_test_file.c_str()); | ||
115 | ensure("number of changed settings loaded", (results == 1)); | ||
116 | ensure("value of changed settings loaded", (test_cg.getU32("TestSetting") == 13)); | ||
117 | } | ||
118 | |||
119 | //priorities | ||
120 | template<> template<> | ||
121 | void control_group_t::test<3>() | ||
122 | { | ||
123 | int results = mCG->loadFromFile(mTestConfigFile.c_str()); | ||
124 | LLControlVariable* control = mCG->getControl("TestSetting"); | ||
125 | LLSD new_value = 13; | ||
126 | control->setValue(new_value, FALSE); | ||
127 | ensure_equals("value of changed setting", mCG->getU32("TestSetting"), 13); | ||
128 | LLControlGroup test_cg; | ||
129 | LLString temp_test_file = (mTestConfigDir + "setting_llsd_persist_temp.xml"); | ||
130 | mCG->saveToFile(temp_test_file.c_str(), TRUE); | ||
131 | results = test_cg.loadFromFile(temp_test_file.c_str()); | ||
132 | //If we haven't changed any settings, then we shouldn't have any settings to load | ||
133 | ensure("number of non-persisted changed settings loaded", (results == 0)); | ||
134 | } | ||
135 | |||
136 | //listeners | ||
137 | template<> template<> | ||
138 | void control_group_t::test<4>() | ||
139 | { | ||
140 | int results = mCG->loadFromFile(mTestConfigFile.c_str()); | ||
141 | ensure("number of settings", (results == 1)); | ||
142 | mCG->getControl("TestSetting")->getSignal()->connect(boost::bind(&this->handleListenerTest, _1)); | ||
143 | mCG->setU32("TestSetting", 13); | ||
144 | ensure("listener fired on changed setting", mListenerFired); | ||
145 | } | ||
146 | |||
147 | } | ||