📄 reference.cpp
字号:
try { // Dot in the wrong spot (before a -) CIMObjectPath h3("//usopen.-9.usta-1-a.org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Two dots in a row CIMObjectPath h4("//usopen-9.usta-1-a..org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Trailing dot CIMObjectPath h5("//usopen-9.usta-1-a.org.:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected);}void test02(){ // test cases with commas in the key value string CIMObjectPath testr1 = CIMObjectPath ("MyClass.z=true,y=1234,x=\"Hello,World\""); CIMObjectPath testr2 = CIMObjectPath ("MyClass.z=true,y=1234,x=\"Hello World,\""); CIMObjectPath testr3 = CIMObjectPath ("MyClass.z=true,y=1234,x=\"Hello,,World\""); CIMObjectPath testr4 = CIMObjectPath ("//atp:77/root/cimv25:test.last=\"Rafter,Smith.Jones long_name:any*char=any123%#@!<>?+^\",first=\"Patrick\""); // test cases with colon inside keybinding string value CIMObjectPath testc1 = CIMObjectPath ("MyClass.z=true,y=1234,x=\"Hello:World\""); Boolean colonException = false; try { CIMObjectPath testc2 = CIMObjectPath ("MyNamespace.ns:MyClass.z=true,y=1234,x=\"Hello:World\""); } catch (Exception&) { colonException = true; } PEGASUS_TEST_ASSERT(colonException); // test error cases Boolean errorDetected = false; try { CIMObjectPath testerr1 = CIMObjectPath ("myclass.X=\"Hello World\"Z=trueY=1234"); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { CIMObjectPath testerr2 = CIMObjectPath ("myclass.XYZ"); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { CIMObjectPath testerr3 = CIMObjectPath ("MyClass.z=true,y=1234abc,x=\"Hello World\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { CIMObjectPath testerr4 = CIMObjectPath ("MyClass.z=nottrue,y=1234,x=\"Hello World\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected);}// Test CIMKeyBinding constructor (CIMValue variety) and equal(CIMValue) methodvoid test03(){ CIMKeyBinding kb0("test0", Real32(3.14159)); PEGASUS_TEST_ASSERT(kb0.equal(Real32(3.14159))); PEGASUS_TEST_ASSERT(!kb0.equal(Real32(3.141593))); CIMKeyBinding kb1("test1", String("3.14159"), CIMKeyBinding::NUMERIC); PEGASUS_TEST_ASSERT(kb1.equal(Real32(3.14159))); PEGASUS_TEST_ASSERT(!kb1.equal(String("3.14159"))); CIMKeyBinding kb2("test2", Uint32(1000)); PEGASUS_TEST_ASSERT(kb2.equal(Uint32(1000))); PEGASUS_TEST_ASSERT(!kb2.equal(Uint32(1001))); PEGASUS_TEST_ASSERT(kb2.getValue() == "1000"); CIMKeyBinding kb3("test3", Char16('X')); PEGASUS_TEST_ASSERT(kb3.equal(Char16('X'))); PEGASUS_TEST_ASSERT(!kb3.equal(Char16('Y'))); PEGASUS_TEST_ASSERT(kb3.getValue() == "X"); CIMKeyBinding kb4("test4", CIMDateTime("19991224120000.000000+360")); PEGASUS_TEST_ASSERT(kb4.equal(CIMDateTime("19991224120000.000000+360"))); PEGASUS_TEST_ASSERT(!kb4.equal(CIMDateTime("19991225120000.000000+360"))); PEGASUS_TEST_ASSERT(kb4.getValue() == "19991224120000.000000+360"); kb4.setValue("0"); PEGASUS_TEST_ASSERT(!kb4.equal(CIMDateTime("19991224120000.000000+360"))); CIMKeyBinding kb5("test5", String("StringTest")); PEGASUS_TEST_ASSERT(kb5.equal(String("StringTest"))); PEGASUS_TEST_ASSERT(!kb5.equal(String("StringTest1"))); PEGASUS_TEST_ASSERT(kb5.getValue() == "StringTest"); CIMKeyBinding kb6("test6", Boolean(true)); PEGASUS_TEST_ASSERT(kb6.equal(Boolean(true))); PEGASUS_TEST_ASSERT(!kb6.equal(Boolean(false))); PEGASUS_TEST_ASSERT(kb6.getValue() == "TRUE"); kb6.setValue("true1"); PEGASUS_TEST_ASSERT(!kb6.equal(Boolean(true))); CIMKeyBinding kb7("test7", CIMObjectPath("//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\",first=\"Patrick\"")); String path = "//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\",first=\"Patrick\""; PEGASUS_TEST_ASSERT(kb7.equal(CIMObjectPath(path))); path = "//atp:77/root/cimv25:TennisPlayer.FIRST=\"Patrick\",LAST=\"Rafter\""; PEGASUS_TEST_ASSERT(kb7.equal(CIMObjectPath(path))); path = "//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\""; PEGASUS_TEST_ASSERT(!kb7.equal(CIMObjectPath(path))); Boolean exceptionFlag = false; try { CIMKeyBinding kb8("test8", Array<Uint32>()); } catch (TypeMismatchException&) { exceptionFlag = true; } PEGASUS_TEST_ASSERT(exceptionFlag); CIMKeyBinding kb9("test9", String("1000"), CIMKeyBinding::STRING); PEGASUS_TEST_ASSERT(!kb9.equal(Uint32(1000))); CIMKeyBinding kb10("test10", String("100"), CIMKeyBinding::NUMERIC); PEGASUS_TEST_ASSERT(kb10.equal(Uint64(100))); PEGASUS_TEST_ASSERT(kb10.equal(Uint32(100))); PEGASUS_TEST_ASSERT(kb10.equal(Uint16(100))); PEGASUS_TEST_ASSERT(kb10.equal(Uint8(100))); PEGASUS_TEST_ASSERT(kb10.equal(Sint64(100))); PEGASUS_TEST_ASSERT(kb10.equal(Sint32(100))); PEGASUS_TEST_ASSERT(kb10.equal(Sint16(100))); PEGASUS_TEST_ASSERT(kb10.equal(Sint8(100))); PEGASUS_TEST_ASSERT(!kb10.equal(String("100"))); CIMKeyBinding kb11("test11", String("+100"), CIMKeyBinding::NUMERIC); PEGASUS_TEST_ASSERT(!kb11.equal(Uint64(100))); // Unsigned ints may not start with "+" PEGASUS_TEST_ASSERT(!kb11.equal(Uint32(100))); PEGASUS_TEST_ASSERT(!kb11.equal(Uint16(100))); PEGASUS_TEST_ASSERT(!kb11.equal(Uint8(100))); PEGASUS_TEST_ASSERT(kb11.equal(Sint64(100))); PEGASUS_TEST_ASSERT(kb11.equal(Sint32(100))); PEGASUS_TEST_ASSERT(kb11.equal(Sint16(100))); PEGASUS_TEST_ASSERT(kb11.equal(Sint8(100))); PEGASUS_TEST_ASSERT(!kb11.equal(String("100")));}//// Test identical() function with keys that are references//void test04(){ // // Create classes A and B referenced classes, C - Association // CIMClass classA (CIMName ("A"), CIMName ()); CIMProperty propertyX ("x", String ()); propertyX.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyY ("y", String ()); propertyY.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyZ ("z", String ()); propertyZ.addQualifier (CIMQualifier (CIMName ("Key"), true)); classA.addProperty (propertyX); classA.addProperty (propertyY); classA.addProperty (propertyZ); CIMClass classB ("B"); CIMProperty propertyQ ("q", String ()); propertyQ.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyR ("r", String ()); propertyR.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyS ("s", String ()); propertyS.addQualifier (CIMQualifier (CIMName ("Key"), true)); classB.addProperty (propertyQ); classB.addProperty (propertyR); classB.addProperty (propertyS); CIMClass classC ("C"); CIMProperty propertyA ("a", CIMValue ()); propertyA.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyB ("b", CIMValue ()); propertyB.addQualifier (CIMQualifier (CIMName ("Key"), true)); classC.addProperty (propertyA); classC.addProperty (propertyB); // // Create instances of each classa // CIMInstance instanceA (CIMName ("A")); instanceA.addProperty (CIMProperty (CIMName ("x"), String ("rose"))); instanceA.addProperty (CIMProperty (CIMName ("y"), String ("lavender"))); instanceA.addProperty (CIMProperty (CIMName ("z"), String ("rosemary"))); CIMObjectPath aPath = instanceA.buildPath (classA); CIMObjectPath aPath2 ("A.y=\"lavender\",x=\"rose\",z=\"rosemary\""); PEGASUS_TEST_ASSERT (aPath.identical (aPath2)); CIMInstance instanceB (CIMName ("B")); instanceB.addProperty (CIMProperty (CIMName ("q"), String ("pelargonium"))); instanceB.addProperty (CIMProperty (CIMName ("r"), String ("thyme"))); instanceB.addProperty (CIMProperty (CIMName ("s"), String ("sage"))); // Test to assure that the buildpath function works. CIMObjectPath bPath = instanceB.buildPath (classB); CIMObjectPath bPath2 ("B.s=\"sage\",q=\"pelargonium\",r=\"thyme\""); PEGASUS_TEST_ASSERT (bPath.identical (bPath2)); // Build instance of C and build path from buildPath function. CIMInstance instanceC (CIMName ("C")); instanceC.addProperty (CIMProperty (CIMName ("a"), aPath, 0, CIMName ("A"))); instanceC.addProperty (CIMProperty (CIMName ("b"), bPath, 0, CIMName ("B"))); CIMObjectPath cPath = instanceC.buildPath (classC); // Build CIMObjectPath from keybindings. Array <CIMKeyBinding> keyBindings; CIMKeyBinding aBinding ("a", "A.y=\"lavender\",x=\"rose\",z=\"rosemary\"", CIMKeyBinding::REFERENCE); CIMKeyBinding bBinding ("b", "B.s=\"sage\",q=\"pelargonium\",r=\"thyme\"", CIMKeyBinding::REFERENCE); keyBindings.append (aBinding); keyBindings.append (bBinding); CIMObjectPath cPath2 ("", CIMNamespaceName (), cPath.getClassName (), keyBindings); // Assert that the CIMObjectPaths for C from build path and direct from keybindings are equal. PEGASUS_TEST_ASSERT (cPath.identical (cPath2)); // ATTN: KS 25 Feb 2003 P3 - Think we can extend these tests since this is creation of classes and // instnaces for associations and referenced classes.}// Test handling of escape charactersvoid test05(){ // Test '\' and '"' characters in a key value // This represents MyClass.key1="\\\"\"\\",key2="\"\"\"\"\\\\\\\\" String s1 = "MyClass.key1=\"\\\\\\\"\\\"\\\\\"," "key2=\"\\\"\\\"\\\"\\\"\\\\\\\\\\\\\\\\\""; CIMObjectPath r1 = s1; PEGASUS_TEST_ASSERT(r1.toString() == s1); // Catch invalid escape sequences in a key value Boolean errorDetected; // Invalid trailing backslash errorDetected = false; try { CIMObjectPath r1("MyClass.key1=\"\\\""); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Invalid "\n" sequence errorDetected = false; try { CIMObjectPath r1("MyClass.key1=\"\\n\""); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Invalid hex sequence errorDetected = false; try { CIMObjectPath r1("MyClass.key1=\"\\x000A\""); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected);}// Test CIMKeyBinding operator==void test06(){ CIMKeyBinding kb1; CIMKeyBinding kb2; // Key bindings of different types are not equal kb1 = CIMKeyBinding("a", "true", CIMKeyBinding::BOOLEAN); kb2 = CIMKeyBinding("a", "true", CIMKeyBinding::STRING); PEGASUS_TEST_ASSERT(!(kb1 == kb2)); // Key bindings with different names are not equal kb1 = CIMKeyBinding("a", "true", CIMKeyBinding::BOOLEAN); kb2 = CIMKeyBinding("b", "true", CIMKeyBinding::BOOLEAN); PEGASUS_TEST_ASSERT(!(kb1 == kb2)); // Key bindings names are not case sensitive kb1 = CIMKeyBinding("a", "true", CIMKeyBinding::BOOLEAN); kb2 = CIMKeyBinding("A", "true", CIMKeyBinding::BOOLEAN); PEGASUS_TEST_ASSERT(kb1 == kb2); // Boolean key bindings are not case sensitive kb1 = CIMKeyBinding("a", "true", CIMKeyBinding::BOOLEAN); kb2 = CIMKeyBinding("a", "TrUe", CIMKeyBinding::BOOLEAN); PEGASUS_TEST_ASSERT(kb1 == kb2); // Boolean key bindings are not equal if they differ other than in case kb1 = CIMKeyBinding("a", "true", CIMKeyBinding::BOOLEAN); kb2 = CIMKeyBinding("a", "truee", CIMKeyBinding::BOOLEAN); PEGASUS_TEST_ASSERT(!(kb1 == kb2));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -