📄 tomof.cpp
字号:
MofWriter::appendClassElement(tmp, class1); // compare with the following result.#define MESSAGE "\n// Class MyClass\n\n\[q1 (55) : DisableOverride, Restricted, \n\q2 (\"Hello\") : DisableOverride, Restricted]\n\class MyClass : YourClass\n\{\n\string message = \"Hello\";\n\uint32 count = 77;\n\boolean isActive(string hostname, uint32 port);\n\};\n"; char classCompare[] = MESSAGE; PEGASUS_TEST_ASSERT(resultTest(tmp, classCompare)); CIMInstance instance1 = class1.buildInstance(false, false, CIMPropertyList()); Buffer tmpInstance; MofWriter::appendInstanceElement(tmpInstance, instance1);#define MESSAGEINST "\n//Instance of MyClass\n\instance of MyClass\n\{\n\message = \"Hello\";\n\count = 77;\n\};\n"; char instanceCompare[] = MESSAGEINST; PEGASUS_TEST_ASSERT(resultTest(tmpInstance, instanceCompare)); } // Test CimClass This is not really an association class. We // simply used the { if (verbose) cout << "Class test\n"; CIMClass class1(CIMName ("MyClass"), CIMName ("YourClass")); Array<String> arr; arr.append("One"); arr.append("Two"); arr.append("Three"); CIMValue v(arr); class1 .addQualifier(CIMQualifier(CIMName ("association"), true)) .addQualifier(CIMQualifier(CIMName ("q1"), Uint32(55))) .addQualifier(CIMQualifier(CIMName ("q2"), String("Hello"))) .addProperty(CIMProperty(CIMName ("message"), CIMValue(CIMTYPE_STRING, false))) .addProperty(CIMProperty(CIMName ("count"), CIMValue(CIMTYPE_UINT32, false))) .addProperty(CIMProperty(CIMName ("booltest"), CIMValue(CIMTYPE_BOOLEAN, false))) .addProperty(CIMProperty(CIMName ("arraytest"), v)) .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING)) .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32))); if (verbose) XmlWriter::printClassElement(class1); Buffer tmp; MofWriter::appendClassElement(tmp, class1); // compare with the following result.#define MESSAGE2 "\n// Class MyClass\n\n\[association : DisableOverride, Restricted, \n\q1 (55) : DisableOverride, Restricted, \n\q2 (\"Hello\") : DisableOverride, Restricted]\n\class MyClass : YourClass\n\{\n\string message;\n\uint32 count;\n\boolean booltest;\n\string arraytest[] = {\"One\", \"Two\", \"Three\"};\n\boolean isActive(string hostname, uint32 port);\n\};\n"; char classCompare[] = MESSAGE2; PEGASUS_TEST_ASSERT(resultTest(tmp, classCompare)); CIMInstance instance1 = class1.buildInstance(false, false, CIMPropertyList()); Buffer tmpInstance; MofWriter::appendInstanceElement(tmpInstance, instance1);#define MESSAGEINST2 "\n//Instance of MyClass\n\instance of MyClass\n\{\n\message = NULL;\n\count = NULL;\n\booltest = NULL;\n\arraytest = {\"One\", \"Two\", \"Three\"};\n\};\n"; char instanceCompare[] = MESSAGEINST2; PEGASUS_TEST_ASSERT(resultTest(tmpInstance, instanceCompare)); } // Test CimClass This is not really an association class. /* [abstract] class class1 { [read] string DriveLetter; [read, Units("KiloBytes")] sint32 RawCapacity = 0; [write] string VolumeLabel; boolean NoParmsMethod(); [Dangerous] boolean OneParmMethod([in] boolean FastFormat); }; */ { CIMClass class1(CIMName ("SubClass"), CIMName ("SuperClass")); class1 .addQualifier(CIMQualifier(CIMName ("abstract"), true)) .addQualifier(CIMQualifier(CIMName ("description"), String("This is a Description of my class. " "This is part 2 of the string to make it longer. " "This is part 3 of the same string for nothing."))) .addProperty(CIMProperty(CIMName ("DriveLetter"), String("A")) .addQualifier(CIMQualifier(CIMName ("read"), true))) .addProperty(CIMProperty(CIMName ("RawCapacity"),Sint32(99)) .addQualifier(CIMQualifier(CIMName ("read"), true)) .addQualifier(CIMQualifier(CIMName ("Units"), String("KiloBytes")))) .addProperty(CIMProperty(CIMName ("VolumeLabel"), String(" "))) .addMethod(CIMMethod(CIMName ("NoParmsMethod"), CIMTYPE_BOOLEAN)) .addMethod(CIMMethod(CIMName ("OneParmmethod"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("FastFormat"), CIMTYPE_BOOLEAN) .addQualifier(CIMQualifier(CIMName ("Dangerous"), true)) ) ) .addMethod(CIMMethod(CIMName ("TwoParmMethod"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("FirstParam"), CIMTYPE_BOOLEAN) .addQualifier(CIMQualifier(CIMName ("Dangerous"), true)) .addQualifier(CIMQualifier(CIMName ("in"),true)) ) .addParameter(CIMParameter(CIMName ("SecondParam"), CIMTYPE_BOOLEAN) .addQualifier(CIMQualifier(CIMName ("Dangerous"), true)) .addQualifier(CIMQualifier(CIMName ("in"),true)) ) ) ; if (verbose) XmlWriter::printClassElement(class1); Buffer tmp; MofWriter::appendClassElement(tmp, class1);#define MESSAGE3 "\n// Class SubClass\n\n\[abstract : DisableOverride, Restricted, \n\description (\"This is a Description of my class. This is part 2 of the string to make it longer. \This is part 3 of the same string for nothing.\") : DisableOverride, Restricted]\n\class SubClass : SuperClass\n\{\n\[read : DisableOverride, Restricted]\n\string DriveLetter = \"A\";\n\[read : DisableOverride, Restricted, \n\Units (\"KiloBytes\") : DisableOverride, Restricted]\n\sint32 RawCapacity = 99;\n\string VolumeLabel = \" \";\n\boolean NoParmsMethod();\n\boolean OneParmmethod([Dangerous : DisableOverride, Restricted] boolean FastFormat);\n\boolean TwoParmMethod([Dangerous : DisableOverride, Restricted, \n\in : DisableOverride, Restricted] boolean FirstParam, [Dangerous : DisableOverride, Restricted, \n\in : DisableOverride, Restricted] boolean SecondParam);\n\};\n"; char classCompare[] = MESSAGE3; PEGASUS_TEST_ASSERT(resultTest(tmp, classCompare)); }}int main(int argc, char** argv){ verbose = getenv("PEGASUS_TEST_VERBOSE"); // Test values MOF generation //Array<Uint32> aa; //CIMValue vv(aa); test01(Boolean(true), "TRUE"); test01(Boolean(false), "FALSE"); test01(Char16('Z'), "Z"); test01(Uint8(77), "77"); test01(Sint8(-77), "-77"); test01(Sint16(77), "77"); test01(Sint16(-77), "-77"); test01(Sint32(77), "77"); test01(Sint32(-77), "-77"); test01(Sint64(77), "77"); test01(Sint64(-77), "-77"); /* The following Tests are not Portable so are excluded test01(Real32(1.5), "1.5000000000000000e+00"); test01(Real64(55.5), "5.5500000000000000e+01"); */ test01(Uint64(123456789), "123456789"); test01(Sint64(-123456789), "-123456789"); test01(CIMObjectPath("MyClass.key1=20,key2=\"my name\""), "\"MyClass.key1=20,key2=\\\"my name\\\"\""); test01(CIMDateTime("19991224120000.000000-300"), "\"19991224120000.000000-300\""); // Test for array values generation of MOF. // Note that we do not test all types. Array<String> arr; arr.append("One"); arr.append("Two"); arr.append("Three"); CIMValue v(arr); test01(arr ,"{\"One\", \"Two\", \"Three\"}" ); Array<Uint32> arr2; arr2.append(1); arr2.append(2); arr2.append(3); test01(arr2, "{1, 2, 3}"); // test property MOF generation test03(); // Qualifier Declaration test04(); // Test Class and Instance mof generation test05(); cout << argv[0] << " +++++ passed all tests" << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -