PEP 55 Update license on source files to current license text and date
[tpot/pegasus/.git] / src / Pegasus / Compiler / tests / CompAssoc / CompAssoc.cpp
1 //%2003////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 // 
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author:
27 //
28 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 //              (carolann_graves@hp.com)
30 //
31 //%/////////////////////////////////////////////////////////////////////////////
32
33 #include <Pegasus/Common/Config.h>
34 #include <cassert>
35 #include <Pegasus/Common/String.h>
36 //#include <Pegasus/Compiler/cimmofParser.h>
37 #include <Pegasus/Repository/CIMRepository.h>
38
39 PEGASUS_USING_PEGASUS;
40 PEGASUS_USING_STD;
41
42 void TestAssociations(CIMRepository& r)
43 {
44     String nameSpace = "root";
45     {
46         CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\"");
47
48         Array<CIMObjectPath> names = r.associatorNames(
49             nameSpace,
50             instanceName,
51             CIMName ("A"),
52             CIMName ("Y"),
53             "left",
54             "right");
55
56         assert(names.size() == 1);
57         Boolean cond = names[0] == CIMObjectPath("Y.key=\"John Jones\"");
58         assert(cond);
59     }
60
61     {
62         CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\"");
63
64         Array<CIMObject> result = r.associators(
65             nameSpace,
66             instanceName,
67             CIMName ("a"),
68             CIMName ("y"),
69             "LEFT",
70             "RIGHT");
71
72         assert(result.size() == 1);
73
74         CIMObjectPath cimReference = result[0].getPath ();
75         CIMInstance cimInstance = CIMInstance(result[0]);
76
77         CIMClass tmpClass = r.getClass(nameSpace, cimInstance.getClassName());
78         CIMObjectPath tmpInstanceName = cimInstance.buildPath(tmpClass);
79
80         Boolean t = tmpInstanceName == CIMObjectPath("Y.key=\"John Jones\"");
81         assert(t);
82         // result[0].print();
83     }
84
85     {
86         CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\"");
87
88         Array<CIMObjectPath> result = r.referenceNames(
89             nameSpace,
90             instanceName,
91             CIMName ("A"),
92             "left");
93
94         assert(result.size() == 1);
95
96         CIMObjectPath tmp = CIMObjectPath ("A."
97             "left=\"x.key=\\\"John Smith\\\"\","
98             "right=\"y.key=\\\"John Jones\\\"\"");
99         
100         Boolean cond = (result[0] == tmp);
101         assert(cond);
102     }
103
104     {
105         CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\"");
106
107         Array<CIMObject> result = r.references(
108             nameSpace,
109             instanceName,
110             CIMName ("A"),
111             "left");
112
113         assert(result.size() == 1);
114
115         CIMClass tmpClass = r.getClass(
116             nameSpace, CIMInstance(result[0]).getClassName());
117
118         CIMObjectPath tmpInstanceName = 
119             CIMInstance(result[0]).buildPath(tmpClass);
120
121         CIMObjectPath tmp = CIMObjectPath ("A."
122             "left=\"x.key=\\\"John Smith\\\"\","
123             "right=\"y.key=\\\"John Jones\\\"\"");
124         
125         Boolean cond = (tmpInstanceName == tmp);
126         assert(cond);
127     }
128
129     // Delete all the object we created:
130     {
131         // First delete the association:
132
133         CIMObjectPath assocInstanceName = CIMObjectPath ("A."
134             "left=\"x.key=\\\"John Smith\\\"\","
135             "right=\"y.key=\\\"John Jones\\\"\"");
136
137         r.deleteInstance(nameSpace, assocInstanceName);
138     }
139 }
140
141 int main()
142 {
143     String repositoryRoot;
144     const char* tmpDir = getenv ("PEGASUS_TMP");
145     if (tmpDir == NULL)
146     {
147         repositoryRoot = ".";
148     }
149     else
150     {
151         repositoryRoot = tmpDir;
152     }
153     repositoryRoot.append("/repository");
154
155     try
156     {
157         CIMRepository r (repositoryRoot);
158
159         // TestAssociations(r);
160     }
161     catch (Exception& e)
162     {
163         cerr << e.getMessage() << endl;
164         exit(1);
165     }
166
167     cout << "+++++ passed all tests" << endl;
168
169     return 0;
170 }