Optimized instances size on disk.
[tpot/pegasus/.git] / src / Pegasus / Common / tests / Property / Property.cpp
1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to 
7 // deal in the Software without restriction, including without limitation the 
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 // 
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include <cassert>
30 #include <Pegasus/Common/CIMProperty.h>
31 #include <Pegasus/Common/CIMPropertyList.h>
32
33 PEGASUS_USING_PEGASUS;
34 PEGASUS_USING_STD;
35 static char * verbose;                  // controls test IO
36
37 void test01()
38 {
39     CIMProperty pnull;
40
41     assert(!pnull);
42
43     CIMProperty p1("message", "Hi There");
44     p1.addQualifier(CIMQualifier("Key", true));
45     p1.addQualifier(CIMQualifier("stuff", true));
46     p1.addQualifier(CIMQualifier("stuff2", true));
47     p1.addQualifier(CIMQualifier("Description", "Blah Blah"));
48     CIMConstProperty p2 = p1;
49
50     // Test clone
51     CIMProperty p1clone = p1.clone(true);
52     CIMProperty p2clone = p2.clone(true);
53    
54     // Test print
55
56     if(verbose)
57     {
58            p1.print(cout);
59            p2.print(cout);
60            p1clone.print(cout);
61            p2clone.print(cout);
62     }
63
64     // Test toMof
65        Array<Sint8> mofOut;
66        p1.toMof(mofOut);
67        p2.toMof(mofOut);
68
69     // Test toXml
70        Array<Sint8> xmlOut;
71        p1.toXml(xmlOut);
72        p2.toXml(xmlOut);
73
74     // Test name
75         String name;
76         name = p1.getName();
77         assert(name == "message");
78         name = p2.getName();
79         assert(name == "message");
80
81     // Test type
82         assert(p1.getType() == CIMType::STRING);
83         assert(p2.getType() == CIMType::STRING);
84
85     // Test isKey
86         assert(p1.isKey() == true);
87         assert(p2.isKey() == true);
88
89     // Test getArraySize
90         assert(p1.getArraySize() == 0);
91         assert(p2.getArraySize() == 0);
92
93     // Test getPropagated
94         assert(p1.getPropagated() == false);
95         assert(p2.getPropagated() == false);
96
97     // Tests for Qualifiers
98         assert(p1.findQualifier("stuff") != PEG_NOT_FOUND);
99         assert(p1.findQualifier("stuff2") != PEG_NOT_FOUND);
100         assert(p1.findQualifier("stuff21") == PEG_NOT_FOUND);
101         assert(p1.findQualifier("stuf") == PEG_NOT_FOUND);
102         assert(p1.getQualifierCount() == 4);
103
104         assert(p2.findQualifier("stuff") != PEG_NOT_FOUND);
105         assert(p2.findQualifier("stuff2") != PEG_NOT_FOUND);
106         assert(p2.findQualifier("stuff21") == PEG_NOT_FOUND);
107         assert(p2.findQualifier("stuf") == PEG_NOT_FOUND);
108         assert(p2.getQualifierCount() == 4);
109
110         assert(p1.existsQualifier("stuff"));
111         assert(p1.existsQualifier("stuff2"));
112
113         assert(!p1.existsQualifier("stuff21"));
114         assert(!p1.existsQualifier("stuf"));
115
116         Uint32 posQualifier;
117         posQualifier = p1.findQualifier("stuff");
118         assert(posQualifier != PEGASUS_NOT_FOUND);
119         assert(posQualifier < p1.getQualifierCount());
120
121         p1.removeQualifier(posQualifier);
122         assert(p1.getQualifierCount() == 3);
123         assert(!p1.existsQualifier("stuff"));
124         assert(p1.existsQualifier("stuff2"));
125
126     // Tests for value insertion.
127     {
128            CIMProperty p1("p1", "Hi There");
129            // test for CIMValue and type
130            CIMProperty p2("p2", Uint32(999));
131            // test for CIMValue and type
132
133            //Test getName and setName
134            assert(p1.getName() == "p1");
135            p1.setName("px");
136            assert(p1.getName() == "px");
137
138            assert(p2.getName() == "p2");
139            p2.setName("py");
140            assert(p2.getName() == "py");
141
142            // Test setValue and getValue
143     }
144 }
145
146 void test02()
147 {
148     // Tests for CIMConstProperty methods
149         CIMProperty p1("message", "Hi There");
150         p1.addQualifier(CIMQualifier("Key", true));
151         p1.addQualifier(CIMQualifier("stuff", true));
152         p1.addQualifier(CIMQualifier("stuff2", true));
153         p1.addQualifier(CIMQualifier("Description", "Blah Blah"));
154         CIMConstProperty p2 = p1;
155
156         CIMConstProperty cp1 = p1;
157         CIMConstProperty cp2 = p2;
158         CIMConstProperty cp3("message3", "hello");
159         CIMConstProperty cp1clone = cp1.clone(true);
160
161         if(verbose)
162             cp1.print(cout);
163
164         Array<Sint8> mofOut;
165         cp1.toMof(mofOut);
166         Array<Sint8> xmlOut;
167         cp1.toXml(xmlOut);
168
169         assert(cp1.getName() == "message");
170         assert(cp1.getType() == CIMType::STRING);
171         assert(cp1.isKey() == true);
172         assert(cp1.getArraySize() == 0);
173         assert(cp1.getPropagated() == false);
174
175         assert(cp1.findQualifier("stuff") != PEG_NOT_FOUND);
176         assert(cp1.findQualifier("stuff2") != PEG_NOT_FOUND);
177         assert(cp1.findQualifier("stuff21") == PEG_NOT_FOUND);
178         assert(cp1.findQualifier("stuf") == PEG_NOT_FOUND);
179         assert(cp1.getQualifierCount() == 4);
180  
181         try 
182         {
183             p1.getQualifier(0);
184         }
185         catch(OutOfBounds& e)
186         {
187                         if(verbose)
188                                 cout << "Exception: " << e.getMessage() << endl;        
189         }
190 }
191
192 void test03()
193 {
194     CIMPropertyList list1;
195     CIMPropertyList list2;
196
197     Array<String> names;
198     names.append("property1");
199     names.append("property2");
200     names.append("property3");
201     list1.set(names);
202     list2 = list1;
203
204     list1.clear();
205 }
206
207 int main(int argc, char** argv)
208 {
209     verbose = getenv("PEGASUS_TEST_VERBOSE");
210     try
211     {
212         test01();
213         test02();
214         test03();
215     }
216     catch (Exception& e)
217     {
218         cout << "Exception: " << e.getMessage() << endl;
219     }
220
221     cout << "+++++ passed all tests" << endl;
222
223     return 0;
224 }