void drive_get_misc_functions() { try { // Get function tests CQLValue a1(Uint64(123)); CQLValue a2(Sint64(-123)); CQLValue a3(Real64(25.24)); CQLValue a4(String("Hellow")); CQLValue a5(Boolean(true)); String _date("20040811105625.000000-360"); CIMDateTime date(_date); CQLValue a6(date); String _date1("20040811105626.000000-360"); CIMDateTime date1(_date1); CQLValue a61(date1); String opStr("MyClass.z=true,y=1234,x=\"Hello World\""); CIMObjectPath op(opStr); CQLValue a7(op); const CIMName _cimName(String("CIM_OperatingSystem")); CIMInstance _i1(_cimName); CQLValue a8(_i1); PEGASUS_TEST_ASSERT(a1.getUint() == Uint64(123)); PEGASUS_TEST_ASSERT(a2.getSint() == Sint64(-123)); PEGASUS_TEST_ASSERT(a3.getReal() == Real64(25.24)); PEGASUS_TEST_ASSERT(a4.getString() == String("Hellow")); PEGASUS_TEST_ASSERT(a5.getBool() == Boolean(true)); PEGASUS_TEST_ASSERT(a6.getDateTime() == CIMDateTime(_date)); PEGASUS_TEST_ASSERT(a6 != a61); PEGASUS_TEST_ASSERT(a6 < a61); PEGASUS_TEST_ASSERT(a7.getReference() == CIMObjectPath(opStr)); try { a1.getSint(); PEGASUS_TEST_ASSERT(0); } catch(...) { PEGASUS_TEST_ASSERT(1); } } catch(Exception & e) { cout << e.getMessage() << endl; PEGASUS_TEST_ASSERT(0); } return; }
void Time::DateTime::GetDateParts(int *out_year, int *out_month, int *out_day) const { if (out_year || out_month || out_day) { static_assert(Time::Day > (Sint64(1) << 32), "code below assumes that the 'date' part of a 64-bit timestamp fits in 32 bits"); // number of days from the epoch to the beginning of the stored date int days = divmod_euclid(m_timestamp, Sint64(Time::Day)).first; // work out how many completed cycles, centuries, 'quads' and years we've measured since the epoch // computed such that n400 may be negative, but all other values must be positive int n400, n100, n4, n1; std::tie(n400, days) = divmod_euclid(days, 365 * 400 + 97); // days must be non-negative after this, so we can use truncating division from here std::tie(n100, days) = divmod_trunc(days, 365 * 100 + 24); std::tie(n4, days) = divmod_trunc(days, 365 * 4 + 1); std::tie(n1, days) = divmod_trunc(days, 365); int year = 2001 + 400 * n400 + 100 * n100 + 4 * n4 + n1; int day = days; // the last day in a 400-year or a 4-year cycle are handled incorrectly, // because n100 is calculated assuming each century has 24 (not 25) leaps, // and n1 is calculated assuming each year has 365 (not 366) days // adjust for those mistakes here if (n100 == 4 || n1 == 4) { assert(!((n100 == 4) && (n1 == 4))); --year; day += 365; assert(is_leap_year(year)); } bool leap = is_leap_year(year); int month = 0; while (day >= month_days[leap][month]) { day -= month_days[leap][month++]; assert(month < 12); } if (out_year) { *out_year = year; } if (out_month) { *out_month = month + 1; } if (out_day) { *out_day = day + 1; } } }
// Fill in a caller-provided int with the integer conversion of the value. void Optarg::Value(int& i) const { CString cs = _value.getCString(); const char* s = cs; Boolean valid = true; Uint32 j; for (j = 0; j < strlen (s); j++) { if ((!isdigit (s [j])) && (!isspace (s [j])) && (s [j] != '+') && (s [j] != '-')) { valid = false; break; } } if (valid) { Sint64 i64; if ( !(sscanf (s, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", &i64)) || (i64 != Sint64(Sint32(i64))) ) { throw TypeMismatchException (); } i = Sint32(i64); } else { throw TypeMismatchException (); } }
/* * Method: SetMoney * * Set the player's money * * > player:SetMoney(money) * * Parameters: * * money - the new amount of money, in dollars * * Availability: * * alpha 10 * * Status: * * experimental */ static int l_player_set_money(lua_State *l) { Player *p = LuaObject<Player>::CheckFromLua(1); float m = luaL_checknumber(l, 2); p->SetMoney(Sint64(m*100.0)); return 0; }
/* * Method: AddCrime * * Add a crime to the player's criminal record * * > player:AddCrime(crime, fine) * * Parameters: * * crime - a <Constants.PolitCrime> string describing the crime * * fine - an amount to add to the player's fine * * Availability: * * alpha 10 * * Status: * * stable */ static int l_player_add_crime(lua_State *l) { LuaObject<Player>::CheckFromLua(1); // check that the method is being called on a Player object Sint64 crimeBitset = LuaConstants::GetConstantFromArg(l, "PolitCrime", 2); Sint64 fine = Sint64(luaL_checknumber(l, 3) * 100.0); Polit::AddCrime(crimeBitset, fine); return 0; }
/* * Method: AddMoney * * Add an amount to the player's money * * > money = player:AddMoney(change) * * Parameters: * * change - the amount of money to add to the player's money, in dollars * * Return: * * money - the player's new money, in dollars * * Availability: * * alpha 10 * * Status: * * experimental */ static int l_player_add_money(lua_State *l) { Player *p = LuaObject<Player>::CheckFromLua(1); float a = luaL_checknumber(l, 2); Sint64 m = p->GetMoney() + Sint64(a*100.0); p->SetMoney(m); lua_pushnumber(l, m*0.01); return 1; }
void Time::DateTime::GetTimeParts(int *out_hour, int *out_minute, int *out_second, int *out_microsecond) const { if (out_hour || out_minute || out_second || out_microsecond) { const Sint64 tstamp = divmod_euclid(m_timestamp, Sint64(Time::Day)).second; assert(tstamp >= 0); if (out_microsecond) { *out_microsecond = (tstamp / Time::Microsecond) % 1000000; } const int seconds = (tstamp / Time::Second); assert(seconds >= 0 && seconds < 24*60*60); if (out_hour) { *out_hour = (seconds / 3600); } if (out_minute) { *out_minute = (seconds / 60) % 60; } if (out_second) { *out_second = (seconds / 1) % 60; } } }
static void _table_to_mission(lua_State *l, Mission &m, bool create) { LUA_DEBUG_START(l); // XXX sucky. should report errors that tell you which field is broken lua_getfield(l, -1, "due"); if (create || !lua_isnil(l, -1)) m.due = luaL_checknumber(l, -1); lua_pop(l, 1); lua_getfield(l, -1, "reward"); if (create || !lua_isnil(l, -1)) m.reward = Sint64(luaL_checknumber(l, -1) * 100.0); lua_pop(l, 1); lua_getfield(l, -1, "type"); if (create || !lua_isnil(l, -1)) m.type = luaL_checkstring(l, -1); lua_pop(l, 1); lua_getfield(l, -1, "client"); if (create || !lua_isnil(l, -1)) m.client = luaL_checkstring(l, -1); lua_pop(l, 1); lua_getfield(l, -1, "location"); if (create || !lua_isnil(l, -1)) { SystemPath *sbody = LuaSystemPath::GetFromLua(-1); m.location = *sbody; } lua_pop(l, 1); lua_getfield(l, -1, "status"); if (lua_isnil(l, -1)) { if (create) m.status = Mission::ACTIVE; } else m.status = static_cast<Mission::MissionState>(LuaConstants::GetConstant(l, "MissionStatus", luaL_checkstring(l, -1))); lua_pop(l, 2); LUA_DEBUG_END(l, -1); }
Sint64 LuaChatForm::GetPrice(Equip::Type t) const { lua_State *l = Lua::manager->GetLuaState(); LUA_DEBUG_START(l); _get_trade_function(l, GetAdvert()->ref, "getPrice"); lua_pushinteger(l, GetAdvert()->ref); lua_pushstring(l, EnumStrings::GetString("EquipType", t)); pi_lua_protected_call(l, 2, 1); Sint64 price = Sint64(lua_tonumber(l, -1) * 100.0); lua_pop(l, 1); LUA_DEBUG_END(l, 0); return price; }
NumberLabel *NumberLabel::SetValue(double v) { m_value = v; switch (m_format) { case FORMAT_NUMBER_2DP: SetText(to_string(v, "f.2")); break; case FORMAT_INTEGER: SetText(to_string(Uint32(v+0.5), "u")); break; case FORMAT_PERCENT: SetText(stringf("%0{f.2}%%", v*100.0)); break; case FORMAT_PERCENT_INTEGER: SetText(stringf("%0{u}%%", Uint32(v*100.0+0.5))); break; case FORMAT_MASS_TONNES: SetText(stringf(Lang::NUMBER_TONNES, formatarg("mass", v))); break; case FORMAT_MONEY: SetText(format_money(Sint64(v*100))); break; case FORMAT_DISTANCE_M: SetText(format_distance(v, 3)); break; case FORMAT_DISTANCE_LY: SetText(stringf(Lang::NUMBER_LY, formatarg("distance", v))); break; default: case FORMAT_NUMBER: SetText(to_string(v, "f")); break; } return this; }
// XXX temporary until crime is moved out to Lua properly static int l_player_get_crime(lua_State *l) { LuaObject<Player>::CheckFromLua(1); // check that the method is being called on a Player object Sint64 crimeBitset, fine; Polit::GetCrime(&crimeBitset, &fine); lua_newtable(l); for (Sint64 i = 0; i < 4; i++) { // hardcoding 4 possible Polit::Crime flags if (crimeBitset & (Sint64(1)<<i)) { lua_pushstring(l, EnumStrings::GetString("PolitCrime", 1<<i)); lua_rawseti(l, -2, lua_rawlen(l, -2)+1); } } lua_pushnumber(l, double(fine) * 0.01); return 2; }
int main(int argc, char** argv) { #ifdef IO verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false; if (verbose) cout << "Test CIMValue. To turn off display, compile with IO undefined\n"; #endif // Test the primitive CIMValue types with test01 test01(Boolean(true)); test01(Boolean(false)); test01(Char16('Z')); test01(Uint8(77)); test01(Sint8(-77)); test01(Sint16(77)); test01(Uint16(-77)); test01(Sint32(77)); test01(Uint32(-77)); test01(Sint64(77)); test01(Uint64(-77)); test01(Real32(1.5)); test01(Real64(55.5)); test01(Uint64(123456789)); test01(Sint64(-123456789)); test01(String("Hello world")); test01(CIMDateTime("19991224120000.000000+360")); test01(CIMObjectPath( "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\"")); // Create and populate a declaration context: const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/zzz"); SimpleDeclContext* context = new SimpleDeclContext; context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("counter"), false, CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("classcounter"), false, CIMScope::CLASS)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("min"), String(), CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("max"), String(), CIMScope::PROPERTY)); context->addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName ("Description"), String(), CIMScope::PROPERTY)); CIMClass class1(CIMName ("MyClass")); class1 .addProperty(CIMProperty(CIMName ("count"), Uint32(55)) .addQualifier(CIMQualifier(CIMName ("counter"), true)) .addQualifier(CIMQualifier(CIMName ("min"), String("0"))) .addQualifier(CIMQualifier(CIMName ("max"), String("1")))) .addProperty(CIMProperty(CIMName ("message"), String("Hello")) .addQualifier(CIMQualifier(CIMName ("description"), String("My Message")))) .addProperty(CIMProperty(CIMName ("ratio"), Real32(1.5))); Resolver::resolveClass (class1, context, NAMESPACE); context->addClass(NAMESPACE, class1); // Test a CIMObject that is a CIMClass test01(CIMObject(class1)); // Test a CIMObject that is a CIMInstance CIMInstance instance1(CIMName ("MyClass")); instance1.addQualifier(CIMQualifier(CIMName ("classcounter"), true)); instance1.addProperty(CIMProperty(CIMName ("message"), String("Goodbye"))); Resolver::resolveInstance (instance1, context, NAMESPACE, true); test01(CIMObject(instance1)); testEmbeddedValue<CIMObject>(instance1); testEmbeddedValue<CIMInstance>(instance1); // Test CIMValue arrays Array<Uint8> arr1; arr1.append(11); arr1.append(22); arr1.append(23); test02(arr1); Array<Uint16> arr2; arr2.append(333); arr2.append(444); arr2.append(445); test02(arr2); Array<Uint32> arr3; arr3.append(5555); arr3.append(6666); arr3.append(6667); test02(arr3); Array<Uint64> arr4; arr4.append(123456789); arr4.append(987654321); arr4.append(987654322); test02(arr4); Array<Sint8> arr5; arr5.append(-11); arr5.append(-22); arr5.append(-23); test02(arr5); Array<Sint16> arr6; arr6.append(333); arr6.append(444); arr6.append(555); test02(arr6); Array<Sint32> arr7; arr7.append(555); arr7.append(666); arr7.append(777); test02(arr7); Array<Sint64> arr8; arr8.append(-123456789); arr8.append(-987654321); arr8.append(-987654321); test02(arr8); Array<Boolean> arr9; arr9.append(true); arr9.append(false); arr9.append(false); test02(arr9); Array<Real32> arr10; arr10.append(1.55F); arr10.append(2.66F); arr10.append(3.77F); test02(arr10); Array<Real64> arr11; arr11.append(55.55); arr11.append(66.66); arr11.append(77.77); test02(arr11); Array<Char16> arr12; arr12.append('X'); arr12.append('Y'); arr12.append('Z'); test02(arr12); Array<String> arr13; arr13.append("One"); arr13.append("Two"); arr13.append("Three"); test02(arr13); Array<CIMDateTime> arr14; arr14.append(CIMDateTime ("20020130120000.000000+360")); arr14.append(CIMDateTime ("20020201120000.000000+360")); arr14.append(CIMDateTime ("20020202120000.000000+360")); test02(arr14); Array<CIMObjectPath> arr15; arr15.append(CIMObjectPath( "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\"")); arr15.append(CIMObjectPath( "//host2:88/root/static:Class2.keyA=\"keyAValue\",keyB=" "\"keyBValue\"")); arr15.append(CIMObjectPath( "//host3:99/root/test/static:Class3.keyX=\"keyXValue\"," "keyY=\"keyYValue\"")); test02(arr15); testEmbeddedValueArray<CIMObject>(instance1, NAMESPACE, context); testEmbeddedValueArray<CIMInstance>(instance1, NAMESPACE, context); // Calling remaining Array tests.. CIMDateTime D1("19991224120000.000000+100"); Array<CIMDateTime> arrD1(10,D1); CIMDateTime *D2 = new CIMDateTime("19991224120000.000000+100"); Array<CIMDateTime> arrD2(D2,1); test03(arrD1, arrD2, D2, CIMDateTime("19991224120000.000000+100"), CIMDateTime("29991224120000.000000+100")); delete D2; CIMName cimname1("yourName"); Array<CIMName> arrcimname1(10,cimname1); CIMName *cimname2 = new CIMName("yourName"); Array<CIMName> arrcimname2(cimname2,1); test03(arrcimname1, arrcimname2, cimname2, CIMName("yourName"), CIMName("myName")); delete cimname2; CIMKeyBinding cimbind1(cimname1, "myKey", CIMKeyBinding::STRING); CIMKeyBinding cimbind2(cimname1, "yourKey", CIMKeyBinding::STRING); Array<CIMKeyBinding> arrcimbind1(10,cimbind1); CIMKeyBinding *cimbind3 = new CIMKeyBinding(cimname1, "myKey", CIMKeyBinding::STRING); Array<CIMKeyBinding> arrcimbind2(cimbind3,1); test03(arrcimbind1, arrcimbind2, cimbind3, cimbind1, cimbind2 ); delete cimbind3; CIMNamespaceName cimnamespace1("root/SampleProvider"); Array<CIMNamespaceName> arrcimnamespace1(10,cimnamespace1); CIMNamespaceName *cimnamespace2 = new CIMNamespaceName( "root/SampleProvider"); Array<CIMNamespaceName> arrcimnamespace2(cimnamespace2,1); test03(arrcimnamespace1, arrcimnamespace2, cimnamespace2, CIMNamespaceName("root/SampleProvider"), CIMNamespaceName("root/SampleProvider2")); delete cimnamespace2; Array<Boolean> arrB1(10,true); Boolean *b = new Boolean(true); Array<Boolean> arrB2(b,1); Array<Boolean> arrB3(2); Boolean b1 = true, b2=false; test03(arrB1, arrB2, b, Boolean(true),Boolean(false)); delete b; Array<Real32> arrreal321(10); Real32 creal321(2.5); Array<Real32> arrreal322(10, creal321); Real32 *creal322 = new Real32(2.5); Array<Real32> arrreal323(creal322,1); Array<Real32> arrreal324(arrreal321); test03(arrreal322, arrreal323, creal322,Real32(2.5),Real32(3.5)); delete creal322; Array<Real64> arrreal641(10); Real64 creal641(20000.54321); Array<Real64> arrreal642(10, creal641); Real64 *creal642 = new Real64(20000.54321); Array<Real64> arrreal643(creal642,1); Array<Real64> arrreal644(arrreal641); test03(arrreal642, arrreal643, creal642,Real64(20000.54321), Real64(30000.54321)); delete creal642; Array<Sint16> arrSint161(10); Sint16 cSint161(-2000); Array<Sint16> arrSint162(10, cSint161); Sint16 *cSint162 = new Sint16(-2000); Array<Sint16> arrSint163(cSint162,1); Array<Sint16> arrSint164(arrSint161); test03(arrSint162, arrSint163, cSint162, Sint16(-2000), Sint16(-3000)); delete cSint162; Array<Sint32> arrSint321(10); Sint32 cSint321(-200000000); Array<Sint32> arrSint322(10, cSint321); Sint32 *cSint322 = new Sint32(-200000000); Array<Sint32> arrSint323(cSint322,1); Array<Sint32> arrSint324(arrSint321); test03(arrSint322, arrSint323, cSint322, Sint32(-200000000), Sint32(-300000000)); delete cSint322; Array<Sint64> arrSint641(10); Sint64 cSint641(Sint64(-2000000)*Sint64(10000000) ); Array<Sint64> arrSint642(10, cSint641); Sint64 *cSint642 = new Sint64(Sint64(-2000000)*Sint64(10000000)); Array<Sint64> arrSint643(cSint642,1); Array<Sint64> arrSint644(arrSint641); test03(arrSint642, arrSint643, cSint642,Sint64(-2000000)*Sint64(10000000), Sint64(-3000000)*Sint64(10000000)); delete cSint642; Array<Sint8> arrSint81(10); Sint8 cSint81(-20); Array<Sint8> arrSint82(10, cSint81); Sint8 *cSint82 = new Sint8(-20); Array<Sint8> arrSint83(cSint82,1); Array<Sint8> arrSint84(arrSint81); test03(arrSint82, arrSint83, cSint82, Sint8(-20), Sint8(-22)); delete cSint82; Array<Uint16> arrUint161(10); Uint16 cUint161(200); Array<Uint16> arrUint162(10, cUint161); Uint16 *cUint162 = new Uint16(200); Array<Uint16> arrUint163(cUint162,1); Array<Uint16> arrUint164(arrUint161); test03(arrUint162, arrUint163, cUint162, Uint16(200), Uint16(255)); delete cUint162; Array<Uint32> arrUint321(10); Uint32 cUint321(2000); Array<Uint32> arrUint322(10, cUint321); Uint32 *cUint322 = new Uint32(2000); Array<Uint32> arrUint323(cUint322,1); Array<Uint32> arrUint324(arrUint321); test03(arrUint322, arrUint323, cUint322, Uint32(2000), Uint32(3000)); delete cUint322; Array<Uint64> arrUint641(10); Uint64 cUint641(Uint64(2000000)*Uint64(10000000)); Array<Uint64> arrUint642(10, cUint641); Uint64 *cUint642 = new Uint64(Uint64(2000000)*Uint64(10000000)); Array<Uint64> arrUint643(cUint642,1); Array<Uint64> arrUint644(arrUint641); test03(arrUint642, arrUint643, cUint642,Uint64(2000000)*Uint64(10000000), Uint64(255000)*Uint64(10000000)); delete cUint642; Array<Uint8> arrUint81(10); Uint8 cUint81(200); Array<Uint8> arrUint82(10, cUint81); Uint8 *cUint82 = new Uint8(200); Array<Uint8> arrUint83(cUint82,1); Array<Uint8> arrUint84(arrUint81); test03(arrUint82, arrUint83, cUint82, Uint8(200), Uint8(255)); delete cUint82; Array<Char16> arrChar161(10); Char16 cChar161('Z'); Array<Char16> arrChar162(10, cChar161); Char16 *cChar162 = new Char16('Z'); Array<Char16> arrChar163(cChar162,1); Array<Char16> arrChar164(arrChar161); test03(arrChar162, arrChar163, cChar162, Char16('Z'), Char16('z')); delete cChar162; delete context; cout << argv[0] << " +++++ passed all tests" << endl; return 0; }
void drive_operation() { // Uint64 tests CQLValue a1(Uint64(10)); CQLValue a2(Uint64(15)); CQLValue a3(Uint64(25)); CQLValue a4(Uint64(30)); CQLValue a5(Uint64(150)); PEGASUS_TEST_ASSERT(a1 != a2); PEGASUS_TEST_ASSERT(a5 == a5); PEGASUS_TEST_ASSERT(a1 < a2); PEGASUS_TEST_ASSERT(a2 >= a1); PEGASUS_TEST_ASSERT(a1 <= a2); PEGASUS_TEST_ASSERT(a2 > a1); // Sint64 tests CQLValue b1(Sint64(10)); CQLValue b2(Sint64(15)); CQLValue b3(Sint64(25)); CQLValue b4(Sint64(30)); CQLValue b5(Sint64(150)); PEGASUS_TEST_ASSERT(b1 != b2); PEGASUS_TEST_ASSERT(b5 == b5); PEGASUS_TEST_ASSERT(b1 < b2); PEGASUS_TEST_ASSERT(b2 >= b1); PEGASUS_TEST_ASSERT(b1 <= b2); PEGASUS_TEST_ASSERT(b2 > b1); // Real64 tests CQLValue c1(Real64(10.00)); CQLValue c2(Real64(15.00)); CQLValue c3(Real64(25.00)); CQLValue c4(Real64(30.00)); CQLValue c5(Real64(150.00)); PEGASUS_TEST_ASSERT(c1 != c2); PEGASUS_TEST_ASSERT(c5 == c5); PEGASUS_TEST_ASSERT(c1 < c2); PEGASUS_TEST_ASSERT(c2 >= c1); PEGASUS_TEST_ASSERT(c1 <= c2); PEGASUS_TEST_ASSERT(c2 > c1); // Misc PEGASUS_TEST_ASSERT(a1 == b1); PEGASUS_TEST_ASSERT(a1 == c1); PEGASUS_TEST_ASSERT(b1 == a1); PEGASUS_TEST_ASSERT(b1 == c1); PEGASUS_TEST_ASSERT(c1 == a1); PEGASUS_TEST_ASSERT(c1 == b1); PEGASUS_TEST_ASSERT(a2 != b1); PEGASUS_TEST_ASSERT(a2 != c1); PEGASUS_TEST_ASSERT(b2 != a1); PEGASUS_TEST_ASSERT(b2 != c1); PEGASUS_TEST_ASSERT(c2 != a1); PEGASUS_TEST_ASSERT(c2 != b1); PEGASUS_TEST_ASSERT(a2 >= b1); PEGASUS_TEST_ASSERT(a2 >= c1); PEGASUS_TEST_ASSERT(b2 >= a1); PEGASUS_TEST_ASSERT(b2 >= c1); PEGASUS_TEST_ASSERT(c2 >= a1); PEGASUS_TEST_ASSERT(c2 >= b1); PEGASUS_TEST_ASSERT(a2 <= b3); PEGASUS_TEST_ASSERT(a2 <= c3); PEGASUS_TEST_ASSERT(b2 <= a3); PEGASUS_TEST_ASSERT(b2 <= c3); PEGASUS_TEST_ASSERT(c2 <= a3); PEGASUS_TEST_ASSERT(c2 <= b3); PEGASUS_TEST_ASSERT(a2 > b1); PEGASUS_TEST_ASSERT(a2 > c1); PEGASUS_TEST_ASSERT(b2 > a1); PEGASUS_TEST_ASSERT(b2 > c1); PEGASUS_TEST_ASSERT(c2 > a1); PEGASUS_TEST_ASSERT(c2 > b1); PEGASUS_TEST_ASSERT(a2 < b3); PEGASUS_TEST_ASSERT(a2 < c3); PEGASUS_TEST_ASSERT(b2 < a3); PEGASUS_TEST_ASSERT(b2 < c3); PEGASUS_TEST_ASSERT(c2 < a3); PEGASUS_TEST_ASSERT(c2 < b3); //Overflow testing CQLValue real1(Real64(0.00000001)); CQLValue sint1(Sint64(-1)); CQLValue uint1(Sint64(1)); CQLValue uint2(Uint64(0)); PEGASUS_TEST_ASSERT(uint1 > sint1); PEGASUS_TEST_ASSERT(real1 > sint1); PEGASUS_TEST_ASSERT(uint2 > sint1); PEGASUS_TEST_ASSERT(real1 > uint2); CQLValue real2(Real64(25.00000000000001)); CQLValue real3(Real64(24.99999999999999)); CQLValue sint2(Sint64(25)); CQLValue uint3(Uint64(25)); PEGASUS_TEST_ASSERT(real2 > real3); PEGASUS_TEST_ASSERT(real2 > sint2); PEGASUS_TEST_ASSERT(real2 > uint3); PEGASUS_TEST_ASSERT(real3 < sint2); PEGASUS_TEST_ASSERT(real3 < uint3); // String tests CQLValue d1(String("HELLO")); CQLValue d2(String("HEL")); CQLValue d3(String("LO")); CQLValue d4(String("AHELLO")); CQLValue d5(String("ZHELLO")); PEGASUS_TEST_ASSERT(d1 == d2 + d3); PEGASUS_TEST_ASSERT(d1 != d2 + d4); PEGASUS_TEST_ASSERT(d1 <= d5); PEGASUS_TEST_ASSERT(d1 < d5); PEGASUS_TEST_ASSERT(d1 >= d4); PEGASUS_TEST_ASSERT(d1 > d4); String str1("0x10"); String str2("10"); String str3("10B"); String str4("10.10"); CQLValue e1( str1, CQLValue::Hex); CQLValue e2( str2, CQLValue::Decimal); CQLValue e3( str3, CQLValue::Binary); CQLValue e4( str4, CQLValue::Real); CQLValue e5(Uint64(16)); CQLValue e6(Uint64(10)); CQLValue e7(Uint64(2)); CQLValue e8(Real64(10.10)); PEGASUS_TEST_ASSERT(e1 == e5); PEGASUS_TEST_ASSERT(e2 == e6); PEGASUS_TEST_ASSERT(e3 == e7); PEGASUS_TEST_ASSERT(e4 == e8); Array<Uint64> array1; array1.append(1); array1.append(2); array1.append(3); array1.append(4); array1.append(5); array1.append(6); array1.append(7); array1.append(8); array1.append(9); array1.append(10); Array<Sint64> array2; array2.append(1); array2.append(2); array2.append(3); array2.append(4); array2.append(5); array2.append(6); array2.append(7); array2.append(8); array2.append(9); array2.append(10); array2.append(3); Array<Real64> array3; array3.append(1.00); array3.append(2.00); array3.append(3.00); array3.append(9.00); array3.append(10.00); array3.append(3.00); array3.append(4.00); array3.append(5.00); array3.append(6.00); array3.append(7.00); array3.append(8.00); Array<Uint64> array4; array4.append(1); array4.append(23); array4.append(3); array4.append(4); array4.append(5); array4.append(6); array4.append(7); array4.append(88); array4.append(9); array4.append(10); Array<Sint64> array5; array5.append(-1); array5.append(2); array5.append(3); array5.append(4); array5.append(5); array5.append(-6); array5.append(7); array5.append(8); array5.append(9); array5.append(10); array5.append(-3); Array<Real64> array6; array6.append(1.23); array6.append(2.00); array6.append(3.00); array6.append(9.00); array6.append(10.00); array6.append(3.00); array6.append(4.14); array6.append(5.00); array6.append(6.00); array6.append(7.00); array6.append(8.00); CIMValue cv1(array1); CIMValue cv2(array2); CIMValue cv3(array3); CIMValue cv4(array4); CIMValue cv5(array5); CIMValue cv6(array6); CQLValue vr1(cv1); CQLValue vr2(cv1); CQLValue vr3(cv2); CQLValue vr4(cv3); CQLValue vr5(cv4); CQLValue vr6(cv5); CQLValue vr7(cv6); PEGASUS_TEST_ASSERT(vr1 == vr2); PEGASUS_TEST_ASSERT(vr1 == vr3); PEGASUS_TEST_ASSERT(vr1 == vr4); PEGASUS_TEST_ASSERT(vr4 == vr3); PEGASUS_TEST_ASSERT(vr1 != vr5); PEGASUS_TEST_ASSERT(vr3 != vr6); PEGASUS_TEST_ASSERT(vr4 != vr7); const CIMName _cimName(String("CIM_OperatingSystem")); CIMInstance _i1(_cimName); CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules"))); CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p4(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i1.addProperty(_p1); _i1.addProperty(_p2); _i1.addProperty(_p3); _i1.addProperty(_p4); CIMInstance _i2(_cimName); CIMProperty _p5(CIMName("Description"), CIMValue(String("Dave Rules Everything"))); CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p8(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i2.addProperty(_p5); _i2.addProperty(_p6); _i2.addProperty(_p7); _i2.addProperty(_p8); CQLValue cql1(_i1); CQLValue cql2(_i1); CQLValue cql3(_i2); CQLValue cql4(_i2); //PEGASUS_TEST_ASSERT(cql1 == cql1); return; }
void drive_resolve_primitive() { const char* env = getenv("PEGASUS_HOME"); String repositoryDir(env); repositoryDir.append("/repository"); //String repositoryDir("c:/pegasus-cvs/pegasus/repository"); CIMNamespaceName _ns("root/cimv2"); CIMRepository *_rep = new CIMRepository(repositoryDir); RepositoryQueryContext _query(_ns, _rep); RepositoryQueryContext _query1(_ns, _rep); try { const CQLIdentifier _Id1(String("CIM_OperatingSystem")); _query.insertClassPath(_Id1); const CIMName _cimName(String("CIM_OperatingSystem")); CIMInstance _i1(_cimName); CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules"))); CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p4(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i1.addProperty(_p1); _i1.addProperty(_p2); _i1.addProperty(_p3); _i1.addProperty(_p4); CQLChainedIdentifier ci1( String("CIM_OperatingSystem.CIM_OperatingSystem::Description")); CQLChainedIdentifier ci2(String("CIM_OperatingSystem.CIM_OperatingSystem::EnabledState")); CQLChainedIdentifier ci3( String("CIM_OperatingSystem.CIM_OperatingSystem::CurrentTimeZone")); CQLChainedIdentifier ci4( String("CIM_OperatingSystem.CIM_OperatingSystem::TimeOfLastStateChange")); CQLChainedIdentifier ci5(String( "CIM_OperatingSystem.CIM_EnabledLogicalElement::TimeOfLastStateChange")); CQLChainedIdentifier ci7(String("CIM_OperatingSystem")); CQLChainedIdentifier ci9(String( "CIM_EnabledLogicalElement.CIM_OperatingSystem::CSCreationClassName")); CQLChainedIdentifier ci10(String("CIM_OperatingSystem.CIM_OperatingSystem::Bubba")); CQLValue a1(ci1); CQLValue a2(ci2); CQLValue a3(ci3); CQLValue a4(ci4); CQLValue a5(ci5); CQLValue a7(ci7); CQLValue a9(ci9); CQLValue a10(ci10); CQLValue a11(_query.getClass(CIMName("CIM_OperatingSystem"))); a1.resolve(_i1, _query); a2.resolve(_i1, _query); a3.resolve(_i1, _query); a4.resolve(_i1, _query); a5.resolve(_i1, _query); a7.resolve(_i1, _query); a10.resolve(_i1, _query1); a9.resolve(_i1, _query); PEGASUS_TEST_ASSERT(a1 == CQLValue(String("Dave Rules"))); PEGASUS_TEST_ASSERT(a2 == CQLValue(Uint64(2))); PEGASUS_TEST_ASSERT(a3 == CQLValue(Sint64(-600))); PEGASUS_TEST_ASSERT(a4 == CQLValue( CIMDateTime(String("20040811105625.000000-360")))); PEGASUS_TEST_ASSERT(a5 == CQLValue( CIMDateTime(String("20040811105625.000000-360")))); //PEGASUS_TEST_ASSERT(a7 == CQLValue(_i1)); PEGASUS_TEST_ASSERT(a9.isNull()); PEGASUS_TEST_ASSERT(a10.isNull()); } catch(Exception & e) { cout << e.getMessage() << endl; PEGASUS_TEST_ASSERT(0); } delete _rep; return; }
static void _testValues(void) { WsmToCimRequestMapper mapper((CIMRepository*) 0); // Test simple data types testSimpleType(Boolean(true)); testSimpleType(Boolean(false)); testSimpleType((Sint8)-4); testSimpleType((Sint16)-44); testSimpleType((Sint32)-444); testSimpleType((Sint64)-4444); testSimpleType((Uint8)4); testSimpleType((Uint16)44); testSimpleType((Uint32)444); testSimpleType((Uint64)4444); testSimpleType(Char16('Z')); testSimpleType(Real32(1.5)); testSimpleType(Real64(55.5)); testSimpleType(Uint64(123456789)); testSimpleType(Sint64(-123456789)); testSimpleType(String("Hello world")); // Test special floating point values: NaN, INF, -INF WsmValue wsmf1("NaN"); CIMValue cimf1((Real32)0.0); mapper.convertWsmToCimValue(wsmf1, CIMNamespaceName(), cimf1); PEGASUS_TEST_ASSERT(cimf1.toString() == PEGASUS_NAN); WsmValue wsmf2("INF"); CIMValue cimf2((Real32)0.0); mapper.convertWsmToCimValue(wsmf2, CIMNamespaceName(), cimf2); PEGASUS_TEST_ASSERT(cimf2.toString() == PEGASUS_INF); WsmValue wsmf3("-INF"); CIMValue cimf3((Real32)0.0); mapper.convertWsmToCimValue(wsmf3, CIMNamespaceName(), cimf3); PEGASUS_TEST_ASSERT(cimf3.toString() == PEGASUS_NEG_INF); WsmValue wsmd1("NaN"); CIMValue cimd1((Real64)0.0); mapper.convertWsmToCimValue(wsmd1, CIMNamespaceName(), cimd1); PEGASUS_TEST_ASSERT(cimd1.toString() == PEGASUS_NAN); WsmValue wsmd2("INF"); CIMValue cimd2((Real64)0.0); mapper.convertWsmToCimValue(wsmd2, CIMNamespaceName(), cimd2); PEGASUS_TEST_ASSERT(cimd2.toString() == PEGASUS_INF); WsmValue wsmd3("-INF"); CIMValue cimd3((Real64)0.0); mapper.convertWsmToCimValue(wsmd3, CIMNamespaceName(), cimd3); PEGASUS_TEST_ASSERT(cimd3.toString() == PEGASUS_NEG_INF); // Test datetime CIMDateTime cimDT; mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0012345678901234S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.001234:000")); mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.12345678901234S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.123456:000")); mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0055555555S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005555:000")); mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.00500000S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005000:000")); mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.9999999S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.999999:000")); mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.000000:000")); mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0055S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005500:000")); mapper.convertWsmToCimDatetime("PT10H5M44.0055S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000100544.005500:000")); mapper.convertWsmToCimDatetime("P10Y", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00003652000000.000000:000")); mapper.convertWsmToCimDatetime("P10Y18M", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004201000000.000000:000")); mapper.convertWsmToCimDatetime("P10Y18M40D", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004241000000.000000:000")); mapper.convertWsmToCimDatetime("P10Y18M40DT34H", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242100000.000000:000")); mapper.convertWsmToCimDatetime("P10Y18M40DT34H70M", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242111000.000000:000")); mapper.convertWsmToCimDatetime("P10Y18M40DT34H70M140S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242111220.000000:000")); mapper.convertWsmToCimDatetime("PT70M140S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000011220.000000:000")); mapper.convertWsmToCimDatetime("PT140S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000000220.000000:000")); mapper.convertWsmToCimDatetime("PT5M44.0055S", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000000544.005500:000")); mapper.convertWsmToCimDatetime("2004-12-01", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+000")); mapper.convertWsmToCimDatetime("2004-12-01Z", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+000")); mapper.convertWsmToCimDatetime("2004-12-01+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+120")); mapper.convertWsmToCimDatetime("2004-12-01-11:30", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******-690")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+120")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012-04:15", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200-255")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34Z", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+000")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012Z", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+000")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.00+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0000000+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0000009+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.000001+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000001+120")); mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.1+02:00", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.100000+120")); mapper.convertWsmToCimDatetime("20041201122334.001200+360", cimDT); PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+360")); // Test arrays of simple types Array<Sint8> s8_arr; s8_arr.append(-11); s8_arr.append(-22); testArrayType(s8_arr); Array<Sint16> s16_arr; s16_arr.append(-111); s16_arr.append(-222); testArrayType(s16_arr); Array<Sint32> s32_arr; s32_arr.append(-1111); s32_arr.append(-2222); testArrayType(s32_arr); Array<Sint64> s64_arr; s64_arr.append(-11111); s64_arr.append(-22222); testArrayType(s64_arr); Array<Uint8> u8_arr; u8_arr.append(11); u8_arr.append(22); testArrayType(u8_arr); Array<Uint16> u16_arr; u16_arr.append(111); u16_arr.append(222); testArrayType(u16_arr); Array<Uint32> u32_arr; u32_arr.append(1111); u32_arr.append(2222); testArrayType(u32_arr); Array<Uint64> u64_arr; u64_arr.append(11111); u64_arr.append(22222); testArrayType(u64_arr); Array<Boolean> b_arr; b_arr.append(true); b_arr.append(false); testArrayType(b_arr); Array<Real32> r32_arr; r32_arr.append(Real32(1.5)); r32_arr.append(Real32(2.5)); testArrayType(r32_arr); Array<Real64> r64_arr; r64_arr.append(Real64(11.5)); r64_arr.append(Real64(12.5)); testArrayType(r64_arr); Array<Char16> c16_arr; c16_arr.append(Char16('Z')); c16_arr.append(Char16('X')); testArrayType(c16_arr); Array<CIMDateTime> dt_arr; dt_arr.append(CIMDateTime("19991224120000.000000+360")); dt_arr.append(CIMDateTime("20001224120000.000000+360")); testArrayType(dt_arr); Array<String> str_arr; str_arr.append("Test string 1"); str_arr.append("Test string 2"); testArrayType(str_arr); // Test class URI to class name conversion String classURI = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass"; CIMName cimName = mapper.convertResourceUriToClassName(classURI); PEGASUS_TEST_ASSERT(cimName.getString() == "MyClass"); }
/* * Function: Money * * Create a string representation of the given money value. * * > string = Format.Money(money) * * Parameters: * * money - a money value, in dollars * * Return: * * string - the string representation * * Availability: * * alpha 10 * * Status: * * stable */ static int l_format_money(lua_State *l) { double t = luaL_checknumber(l, 1); lua_pushstring(l, format_money(Sint64(t*100.0)).c_str()); return 1; }
Sint64 SpaceStation::GetPrice(Equip::Type t) const { Sint64 mul = 100 + Pi::game->GetSpace()->GetStarSystem()->GetCommodityBasePriceModPercent(t); return (mul * Sint64(Equip::types[t].basePrice)) / 100; }
void PG_TestPropertyTypes::initialize(CIMOMHandle& cimom) { // save cimom handle _cimom = cimom; // create default instances CIMInstance instance1("PG_TestPropertyTypes"); instance1.addProperty(CIMProperty( "CreationClassName", String("PG_TestPropertyTypes"))); // key instance1.addProperty(CIMProperty("InstanceId", Uint64(1))); //key instance1.addProperty(CIMProperty( "PropertyString", String("PG_TestPropertyTypes_Instance1"))); instance1.addProperty(CIMProperty("PropertyUint8", Uint8(120))); instance1.addProperty(CIMProperty("PropertyUint16", Uint16(1600))); instance1.addProperty(CIMProperty("PropertyUint32", Uint32(3200))); instance1.addProperty(CIMProperty("PropertyUint64", Uint64(6400))); instance1.addProperty(CIMProperty("PropertySint8", Sint8(-120))); instance1.addProperty(CIMProperty("PropertySint16", Sint16(-1600))); instance1.addProperty(CIMProperty("PropertySint32", Sint32(-3200))); instance1.addProperty(CIMProperty("PropertySint64", Sint64(-6400))); instance1.addProperty(CIMProperty("PropertyBoolean", Boolean(1))); instance1.addProperty(CIMProperty("PropertyReal32", Real32(1.12345670123))); instance1.addProperty(CIMProperty( "PropertyReal64", Real64(1.12345678906543210123))); instance1.addProperty(CIMProperty( "PropertyDatetime", CIMDateTime("20010515104354.000000:000"))); // update object path { CIMObjectPath objectPath = instance1.getPath(); Array<CIMKeyBinding> keys; { CIMProperty keyProperty = instance1.getProperty( instance1.findProperty("CreationClassName")); keys.append( CIMKeyBinding(keyProperty.getName(), keyProperty.getValue())); } { CIMProperty keyProperty = instance1.getProperty( instance1.findProperty("InstanceId")); keys.append( CIMKeyBinding(keyProperty.getName(), keyProperty.getValue())); } objectPath.setKeyBindings(keys); instance1.setPath(objectPath); } _instances.append(instance1); CIMInstance instance2("PG_TestPropertyTypes"); instance2.addProperty(CIMProperty( "CreationClassName", String("PG_TestPropertyTypes"))); // key instance2.addProperty(CIMProperty("InstanceId", Uint64(2))); //key instance2.addProperty(CIMProperty( "PropertyString", String("PG_TestPropertyTypes_Instance2"))); instance2.addProperty(CIMProperty("PropertyUint8", Uint8(122))); instance2.addProperty(CIMProperty("PropertyUint16", Uint16(1602))); instance2.addProperty(CIMProperty("PropertyUint32", Uint32(3202))); instance2.addProperty(CIMProperty("PropertyUint64", Uint64(6402))); instance2.addProperty(CIMProperty("PropertySint8", Sint8(-122))); instance2.addProperty(CIMProperty("PropertySint16", Sint16(-1602))); instance2.addProperty(CIMProperty("PropertySint32", Sint32(-3202))); instance2.addProperty(CIMProperty("PropertySint64", Sint64(-6402))); instance2.addProperty(CIMProperty("PropertyBoolean", Boolean(0))); instance2.addProperty(CIMProperty("PropertyReal32", Real32(2.12345670123))); instance2.addProperty(CIMProperty( "PropertyReal64", Real64(2.12345678906543210123))); instance2.addProperty(CIMProperty( "PropertyDatetime", CIMDateTime("20010515104354.000000:000"))); _instances.append(instance2); // update object path { CIMObjectPath objectPath = instance2.getPath(); Array<CIMKeyBinding> keys; { CIMProperty keyProperty = instance2.getProperty( instance2.findProperty("CreationClassName")); keys.append( CIMKeyBinding(keyProperty.getName(), keyProperty.getValue())); } { CIMProperty keyProperty = instance2.getProperty( instance2.findProperty("InstanceId")); keys.append( CIMKeyBinding(keyProperty.getName(), keyProperty.getValue())); } objectPath.setKeyBindings(keys); instance2.setPath(objectPath); } // instance3 to check for negative floating point and exponents CIMInstance instance3("PG_TestPropertyTypes"); instance3.addProperty(CIMProperty( "CreationClassName", String("PG_TestPropertyTypes"))); // key instance3.addProperty(CIMProperty("InstanceId", Uint64(3))); //key instance3.addProperty(CIMProperty( "PropertyString", String("PG_TestPropertyTypes_Instance3"))); instance3.addProperty(CIMProperty("PropertyUint8", Uint8(120))); instance3.addProperty(CIMProperty("PropertyUint16", Uint16(1600))); instance3.addProperty(CIMProperty("PropertyUint32", Uint32(3200))); instance3.addProperty(CIMProperty("PropertyUint64", Uint64(6400))); instance3.addProperty(CIMProperty("PropertySint8", Sint8(-120))); instance3.addProperty(CIMProperty("PropertySint16", Sint16(-1600))); instance3.addProperty(CIMProperty("PropertySint32", Sint32(-3200))); instance3.addProperty(CIMProperty("PropertySint64", Sint64(-6400))); instance3.addProperty(CIMProperty("PropertyBoolean", Boolean(0))); instance3.addProperty(CIMProperty( "PropertyReal32", Real32(-1.12345670123))); instance3.addProperty(CIMProperty( "PropertyReal64", Real64(0.000000012345))); instance3.addProperty(CIMProperty( "PropertyDatetime", CIMDateTime("20060301104354.000000:000"))); // update object path { CIMObjectPath objectPath = instance3.getPath(); Array<CIMKeyBinding> keys; { CIMProperty keyProperty = instance3.getProperty( instance3.findProperty("CreationClassName")); keys.append( CIMKeyBinding(keyProperty.getName(), keyProperty.getValue())); } { CIMProperty keyProperty = instance3.getProperty(instance3.findProperty("InstanceId")); keys.append( CIMKeyBinding(keyProperty.getName(), keyProperty.getValue())); } objectPath.setKeyBindings(keys); instance3.setPath(objectPath); } realValueTestInstance = instance3; }
int main(int , char** argv) { verbose = getenv("PEGASUS_TEST_VERBOSE"); const char* arg0 = argv[0]; CIMClient client; if (!connectToHost(client)) { cerr << "Connection to host failed. Terminating" << endl; exit(1); } Array<CIMObjectPath> paths; // // Create instances that will have specified test properties in them // that we can use for queries. We used the class // Test_CLITestProviderClass because it has a broad set of testable // properties. // String id1 = "PropertyOpTest1"; CIMInstance inst1 = buildInstance(client, id1); { setPropertyValue(inst1,"scalBool", CIMValue(true)); setPropertyValue(inst1,"scalUint8",CIMValue(Uint8(12))); setPropertyValue(inst1,"scalSint8",CIMValue(Sint8(12))); setPropertyValue(inst1,"scalUint16",CIMValue(Uint16(500))); setPropertyValue(inst1,"scalSint16",CIMValue(Sint16(500))); setPropertyValue(inst1,"scalUint32",CIMValue(Uint32(9999))); setPropertyValue(inst1,"scalSint32",CIMValue(Sint32(9999))); setPropertyValue(inst1,"scalUint64",CIMValue(Uint64(9999))); setPropertyValue(inst1,"scalSint64",CIMValue(Sint64(9999))); setPropertyValue(inst1,"scalString",CIMValue(String("String1"))); Array<Uint32> lArrayUint32; lArrayUint32.append(0); lArrayUint32.append(128); lArrayUint32.append(256); lArrayUint32.append(65536); lArrayUint32.append(4294967295); setPropertyValue(inst1,"arrayUint32",CIMValue(lArrayUint32)); } CIMObjectPath p1 = createInstance(client, inst1); paths.append(p1); String id2 = "PropertyOpTest2"; CIMInstance inst2 = buildInstance(client, id2); { setPropertyValue(inst2,"scalBool", CIMValue(false)); setPropertyValue(inst2,"scalUint8",CIMValue(Uint8(20))); setPropertyValue(inst2,"scalSint8",CIMValue(Sint8(8))); setPropertyValue(inst2,"scalUint16",CIMValue(Uint16(1000))); setPropertyValue(inst2,"scalSint16",CIMValue(Sint16(500))); setPropertyValue(inst2,"scalUint32",CIMValue(Uint32(7698))); setPropertyValue(inst2,"scalSint32",CIMValue(Sint32(9999))); setPropertyValue(inst2,"scalUint64",CIMValue(Uint64(9999))); setPropertyValue(inst2,"scalSint64",CIMValue(Sint64(9999))); setPropertyValue(inst2,"scalString",CIMValue(String("String2"))); Array<Uint32> lArrayUint32; lArrayUint32.append(0); lArrayUint32.append(128); lArrayUint32.append(256); lArrayUint32.append(165536); lArrayUint32.append(4294967295); lArrayUint32.append(876543); setPropertyValue(inst2,"arrayUint32",CIMValue(lArrayUint32)); } CIMObjectPath p2 = createInstance(client, inst2); paths.append(p2); // // Execute the query tests // testEnumerate(client, "scalBool = true", 2); testEnumerate(client,"scalUint32 = 7698", 1); testEnumerate(client, "scalString = 'String2'", 1); testEnumerate(client, "arrayUint32[5] = 876543", 1); testEnumerate(client, "ANY arrayUint32 = 876543", 1); testEnumerate(client, "scalString <> 'NoSuchString'", 3); testEnumerate(client, "scalString = 'String2'", 1); // the following are error tests testEnumerate(client, "scalUint32 = 'NotANumber'", 0, CIMStatusCode(15)); testEnumerate(client, "scalUint32 = 123a", 0, CIMStatusCode(15)); testEnumerate(client, "scalbool = 1234", 0, CIMStatusCode(15)); // Test associator CIMObjectPath assoc = CIMObjectPath("Test_CLITestProviderClass.Id=\"Mike\""); testAssociators(client, "scalBool = true",assoc, 1); testAssociators(client, "scalBool = false",assoc, 0); // Cheap test because only possible comparison is cimobject path // and that means building correct object path for the query // KS_TODO create a valid CIMObjectPath and test it. testReferences(client, "scalBool = false", assoc,0); for (Uint32 i = 0; i < paths.size(); i++) { deleteInstance(client,paths[i]); } cout << arg0 << " +++++ passed all tests."; }
// Test CIMKeyBinding constructor (CIMValue variety) and equal(CIMValue) method void 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); // Unsigned ints may not start with "+" PEGASUS_TEST_ASSERT(!kb11.equal(Uint64(100))); 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"))); }
int createErrorInstance(CIMClient& client) { // Build the embedded instance Array<CIMKeyBinding> embeddedPathKeys; CIMName key1Name("key1"); CIMValue key1Value(String("fake-key1")); CIMName key2Name("key2"); CIMValue key2Value(String("fake-key2")); embeddedPathKeys.append(CIMKeyBinding(key1Name, key1Value)); embeddedPathKeys.append(CIMKeyBinding(key2Name, key2Value)); CIMObjectPath embeddedPath( "localhost", TEST_NAMESPACE, CIMName("PG_EmbeddedClass"), embeddedPathKeys); embeddedInstance.reset(new CIMInstance(CIMName("PG_EmbeddedClass"))); //embeddedInstance->setPath(embeddedPath); embeddedInstance->addProperty(CIMProperty(key1Name, key1Value)); embeddedInstance->addProperty(CIMProperty(key2Name, key2Value)); embeddedInstance->addProperty(CIMProperty(CIMName("prop01"), Uint8(234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop02"), Uint16(16234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop03"), Uint32(32234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop04"), Uint64(64234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop05"), Sint8(-234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop06"), Sint16(-16234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop07"), Sint32(-32234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop08"), Sint64(-64234))); embeddedInstance->addProperty(CIMProperty(CIMName("prop09"), Real32(-64234.46))); embeddedInstance->addProperty(CIMProperty(CIMName("prop10"), Real64(-23464234.78))); embeddedInstance->addProperty(CIMProperty(CIMName("prop11"), CIMDateTime(60, true))); // Build the embedded instance Array<CIMKeyBinding> errorPathKeys; CIMName errorKeyName("errorKey"); CIMValue errorKeyValue(String("error key 1")); errorPathKeys.append(CIMKeyBinding(errorKeyName, errorKeyValue)); CIMObjectPath localErrorPath( "localhost", TEST_NAMESPACE, CIMName("PG_EmbeddedError"), errorPathKeys); errorInstance.reset(new CIMInstance(CIMName("PG_EmbeddedError"))); errorInstance->setPath(localErrorPath); errorInstance->addProperty(CIMProperty(errorKeyName, errorKeyValue)); errorInstance->addProperty(CIMProperty(CIMName("EmbeddedInst"), CIMValue(*embeddedInstance))); try { errorPath = client.createInstance(TEST_NAMESPACE, *errorInstance); PEGASUS_STD(cout) << "Created EmbeddedError: " << errorPath.toString() << PEGASUS_STD(endl); errorInstance->setPath(errorPath); } catch (Exception& e) { PEGASUS_STD(cout) << "Exception while creating Error Instance: " << e.getMessage() << PEGASUS_STD(endl); return -1; } return 0; }