/* constructor. */ SecureBasicAuthenticator::SecureBasicAuthenticator() { PEG_METHOD_ENTER(TRC_AUTHENTICATION, "SecureBasicAuthenticator::SecureBasicAuthenticator()"); // Build Authentication parameter realm required for Basic Challenge // e.g. realm="HostName" _realm.assign("realm="); _realm.append(Char16('"')); _realm.append(System::getHostName()); _realm.append(Char16('"')); // Get a user manager instance handler _userManager = UserManager::getInstance(); #ifdef PEGASUS_OS_ZOS ConfigManager* configManager = ConfigManager::getInstance(); if (String::equalNoCase( configManager->getCurrentValue("enableCFZAPPLID"),"true")) # if (__TARGET_LIB__ < 0x410A0000) #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM { // // Enable __passwd() for passticket validation // for APPLID CFZAPPL in this thread. // set_ZOS_ApplicationID(); } else { Logger::put_l(Logger::STANDARD_LOG, ZOS_SECURITY_NAME, Logger::WARNING, MessageLoaderParms( "Security.Authentication.SecureBasicAuthenticator." "APPLID_OMVSAPPL.PEGASUS_OS_ZOS", "CIM server authentication is using application ID OMVSAPPL.")); } pthread_security_np(0,__USERID_IDENTITY,0,NULL,NULL,0); #else #error APPLID support is not available in 64-bit compilation mode before V1R10 #endif //PEGASUS_PLATFORM_ZOS_ZSERIES_IBM #else { _zosAPPLID = "CFZAPPL"; } else {
/* constructor. */ PAMBasicAuthenticator::PAMBasicAuthenticator() { PEG_METHOD_ENTER(TRC_AUTHENTICATION, "PAMBasicAuthenticator::PAMBasicAuthenticator()"); // Build Authentication parameter realm required for Basic Challenge // e.g. realm="HostName" _realm.assign("realm="); _realm.append(Char16('"')); _realm.append(System::getHostName()); _realm.append(Char16('"')); PEG_METHOD_EXIT(); }
Boolean HTTPMessage::lookupHeader( Array<HTTPHeader>& headers_, const String& fieldName, String& fieldValue, Boolean allowNamespacePrefix) { ArrayIterator<HTTPHeader> headers(headers_); for (Uint32 i = 0, n = headers.size(); i < n; i++) { if (String::equalNoCase(headers[i].first, fieldName) || (allowNamespacePrefix && (headers[i].first.size() >= 3) && (headers[i].first[0] >= '0') && (headers[i].first[0] <= '9') && (headers[i].first[1] >= '0') && (headers[i].first[1] <= '9') && (headers[i].first[2] == Char16('-')) && String::equalNoCase(headers[i].first.subString(3), fieldName))) { fieldValue = headers[i].second; return true; } } // Not found: return false; }
__attribute__((weak)) frost$core$Object* frost$core$String$UTF16Iterator$next$R$frost$core$Char16$shim(frost$core$String$UTF16Iterator* p0) { frost$core$Char16 result = frost$core$String$UTF16Iterator$next$R$frost$core$Char16(p0); frost$core$Char16$wrapper* $tmp2; $tmp2 = (frost$core$Char16$wrapper*) frostObjectAlloc(18, (frost$core$Class*) &frost$core$Char16$wrapperclass); $tmp2->value = result; return ((frost$core$Object*) $tmp2); }
Char16 String::toChar16() const { if (UTF8Length() != 1) { throwStringConversion(c_str(), "Char16"); } return Char16(*this); }
inline String DynamicRoutingTable::_getRoutingKey( const CIMName& className, const CIMNamespaceName& namespaceName) const { //ATTN: We don't support wild class names. PEGASUS_ASSERT(!className.isNull()); String key(namespaceName.getString()); key.append(Char16(':')); key.append(className.getString()); return key; }
PEGASUS_NAMESPACE_BEGIN String Guid::getGuid(const String &prefix) { Uint32 seconds(0), milliSeconds(0); System::getCurrentTime(seconds, milliSeconds); CIMValue secondsValue(seconds); CIMValue milliSecondsValue(milliSeconds); String ipAddress; String hostName(System::getHostName()); if ((ipAddress = System::getHostIP(hostName)) == String::EMPTY) { // set default address if everything else failed ipAddress = String("127.0.0.1"); } // change the dots to dashes for (Uint32 i=0; i<ipAddress.size(); i++) { if (ipAddress[i] == Char16('.')) ipAddress[i] = Char16('-'); } return (secondsValue.toString() + milliSecondsValue.toString() + "-" + ipAddress); }
void HTTPMessage::lookupHeaderPrefix( Array<HTTPHeader>& headers_, const String& fieldName, String& prefix) { ArrayIterator<HTTPHeader> headers(headers_); static const char keyword[] = "CIM"; prefix.clear(); for (Uint32 i = 0, n = headers.size(); i < n; i++) { const String &h = headers[i].first; if ((h.size() >= 3) && (h[0] >= '0') && (h[0] <= '9') && (h[1] >= '0') && (h[1] <= '9') && (h[2] == Char16('-'))) { String fieldNameCurrent = h.subString(3); // ONLY fields starting with keyword can have prefixed according // to spec if (String::equalNoCase(fieldNameCurrent, keyword) == false) continue; prefix = h.subString(0,3); // no field name given, just return the first prefix encountered if (fieldName.size() == 0) break; if (String::equalNoCase(fieldNameCurrent, fieldName) == false) prefix.clear(); else break; } } }
// 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 test(char** argv) { verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false; String s1 = "Hello World"; String s2 = s1; String s3(s2); PEGASUS_TEST_ASSERT(String::equal(s1, s3)); // Test append characters to String String s4 = "Hello"; s4.append(Char16(0x0000)); s4.append(Char16(0x1234)); s4.append(Char16(0x5678)); s4.append(Char16(0x9cde)); s4.append(Char16(0xffff)); { #ifdef HAVE_SSTREAM stringstream os; #endif #ifdef HAVE_STRSTREAM ostrstream os; #endif os << s4; #ifdef HAVE_STRSTREAM os.put('\0'); #endif #ifndef PEGASUS_HAS_ICU const char EXPECTED[] = "Hello\\x0000\\x1234\\x5678\\x9CDE\\xFFFF"; #else CString cstr = s4.getCString(); const char * EXPECTED = (const char *)cstr; #endif #ifdef HAVE_SSTREAM string os_str = os.str(); const char* tmp = os_str.c_str(); #endif #ifdef HAVE_STRSTREAM char *tmp = os.str(); #endif PEGASUS_TEST_ASSERT(strcmp(EXPECTED, tmp) == 0); #ifdef PEGASUS_PLATFORM_AIX_RS_IBMCXX os.freeze(false); #else #ifdef HAVE_STRSTREAM delete tmp; #endif #endif } { // Test getCString const char STR0[] = "one two three four"; String s = STR0; PEGASUS_TEST_ASSERT(strcmp(s.getCString(), STR0) == 0); } { // Test remove String s = "abcdefg"; s.remove(3, 3); PEGASUS_TEST_ASSERT(String::equal(s, "abcg")); PEGASUS_TEST_ASSERT(s.size() == 4); s = "abcdefg"; s.remove(3, 4); PEGASUS_TEST_ASSERT(String::equal(s, "abc")); PEGASUS_TEST_ASSERT(s.size() == 3); s = "abcdefg"; s.remove(3); PEGASUS_TEST_ASSERT(String::equal(s, "abc")); PEGASUS_TEST_ASSERT(s.size() == 3); s = "abc"; s.remove(3); PEGASUS_TEST_ASSERT(String::equal(s, "abc")); PEGASUS_TEST_ASSERT(s.size() == 3); s = "abc"; s.remove(0); PEGASUS_TEST_ASSERT(String::equal(s, "")); PEGASUS_TEST_ASSERT(s.size() == 0); s = "abc"; s.remove(0, 1); PEGASUS_TEST_ASSERT(String::equal(s, "bc")); PEGASUS_TEST_ASSERT(s.size() == 2); String t1 = "HELLO"; String t2 = t1; t2.toLower(); PEGASUS_TEST_ASSERT(String::equal(t1, "HELLO")); PEGASUS_TEST_ASSERT(String::equal(t2, "hello")); } { // another test of the append method String t1 = "one"; t1.append(" two"); PEGASUS_TEST_ASSERT(String::equal(t1, "one two")); t1.append(' '); t1.append('t'); t1.append('h'); t1.append('r'); t1.append("ee"); PEGASUS_TEST_ASSERT(String::equal(t1,"one two three")); // used as example in Doc. String test = "abc"; test.append("def"); PEGASUS_TEST_ASSERT(test == "abcdef"); } // Test of the different overload operators { // Test the == overload operator String t1 = "one"; String t2 = "one"; PEGASUS_TEST_ASSERT(t1 == "one"); PEGASUS_TEST_ASSERT("one" == t1); PEGASUS_TEST_ASSERT(t1 == t2); PEGASUS_TEST_ASSERT(t2 == t1); PEGASUS_TEST_ASSERT(String("one") == "one"); const char STR0[] = "one two three four"; String s = STR0; CString tmp = s.getCString(); PEGASUS_TEST_ASSERT(tmp == s); PEGASUS_TEST_ASSERT(s == tmp); } { // Tests of the + Overload operator String t1 = "abc"; String t2 = t1 + t1; PEGASUS_TEST_ASSERT(t2 == "abcabc"); t1 = "abc"; t2 = t1 + "def"; PEGASUS_TEST_ASSERT(t2 == "abcdef"); t1 = "ghi"; PEGASUS_TEST_ASSERT(t1 == "ghi"); // ATTN: the following fails because there // is no single character overload operator // KS: Apr 2001 // t2 = t1 + 'k' + 'l' + 'm' + "nop"; t2 = t1 + "k" + "l" + "m" + "nop"; PEGASUS_TEST_ASSERT(t2 == "ghiklmnop"); PEGASUS_TEST_ASSERT(String::equal(t2,"ghiklmnop")); // add tests for != operator. t1 = "abc"; PEGASUS_TEST_ASSERT(t1 != "ghi"); PEGASUS_TEST_ASSERT(t1 != t2); // add tests for other compare operators // Operater < t1 = "ab"; t2 = "cde"; PEGASUS_TEST_ASSERT(t1 < t2); PEGASUS_TEST_ASSERT(t1 <= t2); PEGASUS_TEST_ASSERT(t2 > t1); PEGASUS_TEST_ASSERT(t2 >=t1); PEGASUS_TEST_ASSERT(String::compare(t1,t2) < 0); PEGASUS_TEST_ASSERT(String::compare(t2,t1) > 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 1) < 0); PEGASUS_TEST_ASSERT(String::compare(t2, t1, 1) > 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 10) < 0); PEGASUS_TEST_ASSERT(String::compare(t2, t1, 10) > 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 0) == 0); t2 = t1; PEGASUS_TEST_ASSERT(t1 <= t2); PEGASUS_TEST_ASSERT(t1 >= t2); PEGASUS_TEST_ASSERT(String::compare(t1, t2) == 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 0) == 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 1) == 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 10) == 0); // Tests for compare with same length t1 = "abc"; t2 = "def"; PEGASUS_TEST_ASSERT(t1 < t2); PEGASUS_TEST_ASSERT(String::compare(t1, t2) < 0); PEGASUS_TEST_ASSERT(String::compare(t2, t1) > 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 10) < 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 0) == 0); t1 = "abc"; t2 = "ABC"; PEGASUS_TEST_ASSERT(String::equalNoCase(t1,t2)); PEGASUS_TEST_ASSERT(!String::equal(t1,t2)); PEGASUS_TEST_ASSERT(String::compareNoCase(t1,t2) == 0); t1.toUpper(); t2.toLower(); PEGASUS_TEST_ASSERT(String::equal(t1, "ABC")); PEGASUS_TEST_ASSERT(String::equal(t2, "abc")); t1 = "1000"; t2 = "1001"; PEGASUS_TEST_ASSERT(String::compareNoCase(t1,t2) < 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2) < 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 3) == 0); PEGASUS_TEST_ASSERT(String::compare(t1, t2, 4) < 0); #ifdef PEGASUS_HAS_ICU // // Strings used to test non-ascii case mappings // Tests context sensitve mappings (eg. greek) // Tests expansion after mapping (eg german) // // Lower case german and greek // --latin small letter sharp s (german) (2 of these to cause // ICU overflow error inside of String) // --greek small letter sigma (followed by another letter) // --latin small a // --greek small letter sigma (NOT followed by another letter) const Char16 lowermap[] = { 0xdf, 0xdf, 0x3c3, 'a', 0x3c2, 0x00}; String degkLow(lowermap); // Needed because the german char does not round trip // after an uppercase followed by lower case. // --latin small letters 's' 's' (4 of these due to expansion) // --greek small letter sigma (followed by another letter) // --latin small a // --greek small letter sigma (NOT followed by another letter) const Char16 lowermap2[] = { 's', 's', 's', 's', 0x3c3, 'a', 0x3c2, 0x00}; String degkLow2(lowermap2); // Upper case greek and german // latin cap letter sharp s (german) (4 of these due to expansion) // greek cap letter sigma (followed by another letter) // latin cap A // greek cap letter sigma (NOT followed by another letter) const Char16 uppermap[] = { 'S', 'S', 'S', 'S', 0x3a3, 'A', 0x3a3, 0x00}; String degkUp(uppermap); PEGASUS_TEST_ASSERT(String::compareNoCase(degkLow,degkUp) == 0); // does a binary compare, so lower > upper PEGASUS_TEST_ASSERT(String::compare(degkLow,degkUp) > 0); PEGASUS_TEST_ASSERT(String::equalNoCase(degkLow,degkUp)); String mapTest(degkLow); mapTest.toUpper(); PEGASUS_TEST_ASSERT(String::equal(mapTest, degkUp)); // Note that the German char does not round trip mapTest.toLower(); PEGASUS_TEST_ASSERT(String::equal(mapTest, degkLow2)); #endif } { // Test of the [] operator String t1 = "abc"; Char16 c = t1[1]; // note c is Char16 PEGASUS_TEST_ASSERT(c == 'b'); //ATTN: test for outofbounds exception try { c = t1[200]; } catch (IndexOutOfBoundsException&) { PEGASUS_TEST_ASSERT(true); } } { // Test the find function String t1 = "abcdef"; String t2 = "cde"; String t3 = "xyz"; String t4 = "abc"; String t5 = "abd"; String t6 = "defg"; PEGASUS_TEST_ASSERT(t1.find('c') == 2); PEGASUS_TEST_ASSERT(t1.find(t2)==2); PEGASUS_TEST_ASSERT(t1.find(t3)==PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(t1.find(t4)==0); PEGASUS_TEST_ASSERT(t1.find(t5)==PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(t1.find(t6)==PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(t1.find("cde")==2); PEGASUS_TEST_ASSERT(t1.find("def")==3); PEGASUS_TEST_ASSERT(t1.find("xyz")==PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(t1.find("a") ==0); // test for the case where string // partly occurs and then later // completely occurs String s = "this is an apple"; PEGASUS_TEST_ASSERT(s.find("apple")==11); PEGASUS_TEST_ASSERT(s.find("appld")==PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(s.find("this")==0); PEGASUS_TEST_ASSERT(s.find("t")==0); PEGASUS_TEST_ASSERT(s.find("e")==15); s = "a"; PEGASUS_TEST_ASSERT(s.find("b")==PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(s.find("a")==0); PEGASUS_TEST_ASSERT(s.find(s)==0); s = "aaaapple"; PEGASUS_TEST_ASSERT(s.find("apple")==3); // 20020715-RK This method was removed from the String class //{ // String nameSpace = "a#b#c"; // nameSpace.translate('#', '/'); // PEGASUS_TEST_ASSERT(nameSpace == "a/b/c"); //} } { // // Test String unicode enablement // char utf8chr[] = { '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D', '\xCE', '\xBD', '\xCE', '\xB9', '\xCE', '\xBA', '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84', '\0' }; // utf8 string with mutliple byte characters Char16 utf16chr[] = { 0x0399,0x03BF,0x03CD,0x03BD,0x03B9, 0x03BA,0x03BF,0x03BD,0x03C4,0x00 }; // utf16 representation of the utf8 string String utf16string(utf16chr); String utf8string(utf8chr); String utf16merge(utf8string.getChar16Data()); CString temp = utf8string.getCString(); CString temp2 = utf16string.getCString(); PEGASUS_TEST_ASSERT(utf16string == utf8string); PEGASUS_TEST_ASSERT(utf16string == utf16merge); PEGASUS_TEST_ASSERT(utf16string == utf16chr); PEGASUS_TEST_ASSERT(utf8string == utf16chr); PEGASUS_TEST_ASSERT(memcmp(utf8string.getChar16Data(), utf16string.getChar16Data(),sizeof(utf16chr)) == 0); PEGASUS_TEST_ASSERT(strcmp(utf8string.getCString(),utf8chr) == 0); PEGASUS_TEST_ASSERT(strcmp(utf16string.getCString(),utf8chr) == 0); PEGASUS_TEST_ASSERT(strcmp(temp,utf8chr) == 0); PEGASUS_TEST_ASSERT(strcmp(temp2,utf8chr) == 0); Uint32 count = 0; Uint32 size = sizeof(utf8chr); while(count<size) { PEGASUS_TEST_ASSERT(isUTF8(&utf8chr[count]) == true); UTF8_NEXT(utf8chr,count); } // utf8 string with mutliple byte characters char utf8bad[] = { '\xFF','\xFF', '\xFF', '\0', '\0', '\0' }; count = 0; size = 3; while(count<size) { PEGASUS_TEST_ASSERT(isUTF8(&utf8bad[count]) == false); UTF8_NEXT(utf8bad,count); } Char16 utf16Chars[] = { 0x6A19, 0x6E96, 0x842C, 0x570B, 0x78BC, 0x042E, 0x043D, 0x0438, 0x043A, 0x043E, 0x0434, 0x110B, 0x1172, 0x1102, 0x1165, 0x110F, 0x1169, 0x11AE, 0x10E3, 0x10DC, 0x10D8, 0x10D9, 0x10DD, 0x10D3, 0x10D8, 0xdbc0, 0xdc01, 0x05D9, 0x05D5, 0x05E0, 0x05D9, 0x05E7, 0x05D0, 0x05B8, 0x05D3, 0x064A, 0x0648, 0x0646, 0x0650, 0x0643, 0x0648, 0x062F, 0x092F, 0x0942, 0x0928, 0x093F, 0x0915, 0x094B, 0x0921, 0x016A, 0x006E, 0x012D, 0x0063, 0x014D, 0x0064, 0x0065, 0x033D, 0x00E0, 0x248B, 0x0061, 0x2173, 0x0062, 0x1EA6, 0xFF21, 0x00AA, 0x0325, 0x2173, 0x249C, 0x0063, 0x02C8, 0x006A, 0x0075, 0x006E, 0x026A, 0x02CC, 0x006B, 0x006F, 0x02D0, 0x0064, 0x30E6, 0x30CB, 0x30B3, 0x30FC, 0x30C9, 0xFF95, 0xFF86, 0xFF7A, 0xFF70, 0xFF84, 0xFF9E, 0xC720, 0xB2C8, 0xCF5B, 0x7D71, 0x4E00, 0x78BC, 0xdbc0, 0xdc01, 0x00}; String ugly(utf16Chars); PEGASUS_TEST_ASSERT(ugly == utf16Chars); // // Test passing bad utf-8 into String // // A utf-8 sequence with a byte zeroed out in a bad spot char utf8bad1[] = { '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D', '\xCE', '\xBD', '\xCE', '\0', '\xCE', '\xBA', '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84', '\0' }; // utf8 string with mutliple byte characters // Test String(char *) try { // the first terminator causes invalid utf-8 String tmp(utf8bad1); PEGASUS_TEST_ASSERT(false); } catch (Exception &) { // expect an error } // Test String(char *, Uint32) try { // bogus utf-8 char in the middle String tmp(utf8bad1, sizeof(utf8bad1)-1); PEGASUS_TEST_ASSERT(false); } catch (Exception &) { // expect an error } // Test String(char *, Uint32) try { // good, but the last utf-8 char extends past the last byte String tmp(utf8chr, sizeof(utf8chr) - 2); PEGASUS_TEST_ASSERT(false); } catch (Exception &) { // expect an error } // Test String::assign(char *) String assigntest(utf8chr); // good so far try { // the first terminator causes invalid utf-8 assigntest.assign(utf8bad1); // bad PEGASUS_TEST_ASSERT(false); } catch (Exception &) { // expect an error } // Test String::assign(char *, Uint32) try { // bogus utf-8 char in the middle assigntest.assign(utf8bad1, sizeof(utf8bad1) - 1); // bad PEGASUS_TEST_ASSERT(false); } catch (Exception &) { // expect an error } // Test String::assign(char *, Uint32) try { // good, but the last utf-8 char extends past the end assigntest.assign(utf8chr, sizeof(utf8chr) - 2); // bad PEGASUS_TEST_ASSERT(false); } catch (Exception &) { // expect an error } // // Test passing in good utf-8 with an embedded terminator // // A utf-8 sequence with a byte zeroed out in an ok spot char utf8good1[] = { '\xCE', '\x99', '\xCE', '\xBF', '\xCF', '\x8D', '\xCE', '\xBD', 'A', '\0', '\xCE', '\xBA', '\xCE', '\xBF', '\xCE', '\xBD', '\xCF', '\x84', '\0' }; // utf8 string with mutliple byte characters // Test String(char *) try { // terminator after 5 chars String tmp(utf8good1); PEGASUS_TEST_ASSERT (tmp.size() == 5); } catch (Exception &) { // didn't see that one coming PEGASUS_TEST_ASSERT(false); } // Test String(char *, Uint32) try { // embedded terminator counts as 1 char String tmp(utf8good1, sizeof(utf8good1) - 1); PEGASUS_TEST_ASSERT (tmp.size() == 10); } catch (Exception &) { // didn't see that one coming PEGASUS_TEST_ASSERT(false); } assigntest.clear(); // Test String::assign(char *) try { // terminator after 5 chars assigntest.assign(utf8good1); PEGASUS_TEST_ASSERT (assigntest.size() == 5); } catch (Exception &) { // didn't see that one coming PEGASUS_TEST_ASSERT(false); } assigntest.clear(); // Test String::assign(char *, Uint32) try { // embedded terminator counts as 1 char assigntest.assign(utf8good1, sizeof(utf8good1) - 1); PEGASUS_TEST_ASSERT (assigntest.size() == 10); } catch (Exception &) { // didn't see that one coming PEGASUS_TEST_ASSERT(false); } // // Casing tests // String little("the quick brown fox jumped over the lazy dog"); String big("THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG"); String tmpBig = big; String tmpLittle = little; tmpBig.toLower(); PEGASUS_TEST_ASSERT(tmpBig == little); tmpBig.toUpper(); PEGASUS_TEST_ASSERT(tmpBig == big); } #if 0 // The match code has been removed from the String class // Test the string match functions { String abc = "abc"; String ABC = "ABC"; PEGASUS_TEST_ASSERT(String::match(abc, "abc")); PEGASUS_TEST_ASSERT(String::match(ABC, "ABC")); PEGASUS_TEST_ASSERT(!String::match(abc, "ABC")); PEGASUS_TEST_ASSERT(!String::match(ABC, "abc")); PEGASUS_TEST_ASSERT(String::matchNoCase(abc, "abc")); PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "abc")); PEGASUS_TEST_ASSERT(String::matchNoCase(abc, "ABC")); PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "ABc")); PEGASUS_TEST_ASSERT(String::match(abc, "???")); PEGASUS_TEST_ASSERT(String::match(ABC, "???")); PEGASUS_TEST_ASSERT(String::match(abc, "*")); PEGASUS_TEST_ASSERT(String::match(ABC, "*")); PEGASUS_TEST_ASSERT(String::match(abc, "?bc")); PEGASUS_TEST_ASSERT(String::match(abc, "?b?")); PEGASUS_TEST_ASSERT(String::match(abc, "??c")); PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "?bc")); PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "?b?")); PEGASUS_TEST_ASSERT(String::matchNoCase(ABC, "??c")); PEGASUS_TEST_ASSERT(String::match(abc, "*bc")); PEGASUS_TEST_ASSERT(String::match(abc, "a*c")); PEGASUS_TEST_ASSERT(String::match(abc, "ab*")); PEGASUS_TEST_ASSERT(String::match(abc, "a*")); // ATTN-RK-P3-20020603: This match code is broken //PEGASUS_TEST_ASSERT(String::match(abc, "[axy]bc")); PEGASUS_TEST_ASSERT(!String::match(abc, "[xyz]bc")); PEGASUS_TEST_ASSERT(!String::match(abc, "def")); PEGASUS_TEST_ASSERT(!String::match(abc, "[de]bc")); // ATTN-RK-P3-20020603: This match code is broken //PEGASUS_TEST_ASSERT(String::match(abc, "a[a-c]c")); PEGASUS_TEST_ASSERT(!String::match(abc, "a[d-x]c")); // ATTN-RK-P3-20020603: This match code does not yet handle escape chars //PEGASUS_TEST_ASSERT(String::match("*test", "\\*test")); PEGASUS_TEST_ASSERT(String::match("abcdef123", "*[0-9]")); PEGASUS_TEST_ASSERT(String::match("This is a test", "*is*")); PEGASUS_TEST_ASSERT(String::matchNoCase("This is a test", "*IS*")); PEGASUS_TEST_ASSERT(String::match("Hello", "Hello")); PEGASUS_TEST_ASSERT(String::matchNoCase("HELLO", "hello")); PEGASUS_TEST_ASSERT(String::match("This is a test", "This is *")); PEGASUS_TEST_ASSERT(String::match("This is a test", "* is a test")); PEGASUS_TEST_ASSERT(!String::match("Hello", "Goodbye")); String tPattern = "When in the * of human*e??nts it be?ome[sS] [0-9] nec*"; try { String x(reinterpret_cast<const char *>(0)); cerr << "Error: Exception not thrown on NULL passed to" " constructor(const char *)" << endl; } catch ( const NullPointer & ) { // This is the exception that should be thrown. } catch ( ... ) { cerr << "Error: Wrong exception thrown on NULL passed to" " constructor(const char *)" << endl; } try { String x(reinterpret_cast<const Char16 *>(0)); cerr << "Error: Exception not thrown on NULL passed to" " constructor(const Char16 *)" << endl; } catch ( const NullPointer & ) { // This is the exception that should be thrown. } catch ( ... ) { cerr << "Error: Wrong exception thrown on NULL passed to" " constructor(const Char16 *)" << endl; } try { String x; x.assign(reinterpret_cast<const char *>(0)); cerr << "Error: Exception not thrown on NULL passed to" " assign(const char *)" << endl; } catch ( const NullPointer & ) { // This is the exception that should be thrown. } catch ( ... ) { cerr << "Error: Wrong exception thrown on NULL passed to" " assign(const char *)" << endl; } try { String x; x.assign(reinterpret_cast<const Char16 *>(0)); cerr << "Error: Exception not thrown on NULL passed to" " assign(const Char16 *)" << endl; } catch ( const NullPointer & ) { // This is the exception that should be thrown. } catch ( ... ) { cerr << "Error: Wrong exception thrown on NULL passed to" " assign(const Char16 *)" << endl; } try { String x; x.append(reinterpret_cast<const char *>(0)); cerr << "Error: Exception not thrown on NULL passed to" " append(const char *)" << endl; } catch ( const NullPointer & ) { // This is the exception that should be thrown. } catch ( ... ) { cerr << "Error: Wrong exception thrown on NULL passed to" " append(const char *)" << endl; } try { String x; x.append(reinterpret_cast<const Char16 *>(0)); cerr << "Error: Exception not thrown on NULL passed to" " append(const Char16 *)" << endl; } catch ( const NullPointer & ) { // This is the exception that should be thrown. } catch ( ... ) { cerr << "Error: Wrong exception thrown on NULL passed" " to append(const Char16 *)" << endl; } // ATTN-RK-P3-20020603: This match code is broken //PEGASUS_TEST_ASSERT(String::match( // "When in the course of human events it becomes 0 necessary", // tPattern)); //PEGASUS_TEST_ASSERT(String::match( // "When in the xyz of human events it becomes 9 necessary", // tPattern)); //PEGASUS_TEST_ASSERT(String::match( // "When in the of human events it becomes 3 necessary", // tPattern)); } #endif // string() { String s; PEGASUS_TEST_ASSERT(s.size() == 0); PEGASUS_TEST_ASSERT(s[0] == '\0'); } // String(const String& s) { const String s("hello"); const String t = s; PEGASUS_TEST_ASSERT(s.size() == strlen("hello")); PEGASUS_TEST_ASSERT(s == "hello"); PEGASUS_TEST_ASSERT(t.size() == strlen("hello")); PEGASUS_TEST_ASSERT(t == "hello"); } // String(const char*) { const String s("hello"); PEGASUS_TEST_ASSERT(s.size() == strlen("hello")); PEGASUS_TEST_ASSERT(s == "hello"); } // reserve() { String s; s.reserveCapacity(100); PEGASUS_TEST_ASSERT(s.size() == 0); // PEGASUS_TEST_ASSERT(s.getCapacity() >= 100); String t("hello world"); PEGASUS_TEST_ASSERT(t.size() == strlen("hello world")); t.reserveCapacity(500); PEGASUS_TEST_ASSERT(t.size() == strlen("hello world")); PEGASUS_TEST_ASSERT(t == "hello world"); } // assign(const String&) { String s("this is a test"); String t; t = s; PEGASUS_TEST_ASSERT(s.size() == strlen("this is a test")); PEGASUS_TEST_ASSERT(s == "this is a test"); PEGASUS_TEST_ASSERT(t.size() == strlen("this is a test")); PEGASUS_TEST_ASSERT(t == "this is a test"); s = t; PEGASUS_TEST_ASSERT(s.size() == strlen("this is a test")); PEGASUS_TEST_ASSERT(s == "this is a test"); PEGASUS_TEST_ASSERT(t.size() == strlen("this is a test")); PEGASUS_TEST_ASSERT(t == "this is a test"); } // assign(const char*, size_t) { const char MESSAGE[] = "x"; const size_t LENGTH = sizeof(MESSAGE) - 1; String s; s.assign(MESSAGE, LENGTH); PEGASUS_TEST_ASSERT(s.size() == LENGTH); PEGASUS_TEST_ASSERT(s == MESSAGE); String t("dummy", 5); t.assign(MESSAGE, LENGTH); PEGASUS_TEST_ASSERT(t.size() == LENGTH); PEGASUS_TEST_ASSERT(t == MESSAGE); } // assign(const char*) { const char MESSAGE[] = "x"; const size_t LENGTH = sizeof(MESSAGE) - 1; String s; s.assign(MESSAGE); PEGASUS_TEST_ASSERT(s.size() == LENGTH); PEGASUS_TEST_ASSERT(s == MESSAGE); String t("dummy", 5); t.assign(MESSAGE); PEGASUS_TEST_ASSERT(t.size() == LENGTH); PEGASUS_TEST_ASSERT(t == MESSAGE); } // append(const String&) { String s; s.append(String("xxx")); PEGASUS_TEST_ASSERT(s.size() == 3); PEGASUS_TEST_ASSERT(s == "xxx"); s.append(String("yyy")); PEGASUS_TEST_ASSERT(s.size() == 6); PEGASUS_TEST_ASSERT(s == "xxxyyy"); s.append(String("zzz")); PEGASUS_TEST_ASSERT(s.size() == 9); PEGASUS_TEST_ASSERT(s == "xxxyyyzzz"); } // append(const char*) { String s; s.append("xxx"); PEGASUS_TEST_ASSERT(s.size() == 3); PEGASUS_TEST_ASSERT(s == "xxx"); s.append("yyy"); PEGASUS_TEST_ASSERT(s.size() == 6); PEGASUS_TEST_ASSERT(s == "xxxyyy"); s.append("zzz"); PEGASUS_TEST_ASSERT(s.size() == 9); PEGASUS_TEST_ASSERT(s == "xxxyyyzzz"); } // append(const char*) { String s; s.append("xxx"); PEGASUS_TEST_ASSERT(s.size() == 3); PEGASUS_TEST_ASSERT(s == "xxx"); s.append("yyy"); PEGASUS_TEST_ASSERT(s.size() == 6); PEGASUS_TEST_ASSERT(s == "xxxyyy"); s.append("zzz"); PEGASUS_TEST_ASSERT(s.size() == 9); PEGASUS_TEST_ASSERT(s == "xxxyyyzzz"); } // append(char) { String s; for (int i = 'a'; i <= 'z'; i++) { Char16 c = i; s.append(c); } PEGASUS_TEST_ASSERT(s.size() == 26); PEGASUS_TEST_ASSERT(s == "abcdefghijklmnopqrstuvwxyz"); } // clear() { String s("abc"); String t = s; String u = s; s.clear(); PEGASUS_TEST_ASSERT(t.size() == 3); PEGASUS_TEST_ASSERT(t == "abc"); PEGASUS_TEST_ASSERT(t[0] == 'a'); PEGASUS_TEST_ASSERT(u.size() == 3); PEGASUS_TEST_ASSERT(u == "abc"); PEGASUS_TEST_ASSERT(u[0] == 'a'); PEGASUS_TEST_ASSERT(s.size() == 0); PEGASUS_TEST_ASSERT(s[0] == '\0'); t.clear(); PEGASUS_TEST_ASSERT(t.size() == 0); PEGASUS_TEST_ASSERT(t[0] == '\0'); PEGASUS_TEST_ASSERT(t == ""); PEGASUS_TEST_ASSERT(u.size() == 3); PEGASUS_TEST_ASSERT(u == "abc"); PEGASUS_TEST_ASSERT(u[0] == 'a'); PEGASUS_TEST_ASSERT(s.size() == 0); PEGASUS_TEST_ASSERT(s == ""); PEGASUS_TEST_ASSERT(s[0] == '\0'); u.clear(); PEGASUS_TEST_ASSERT(t.size() == 0); PEGASUS_TEST_ASSERT(t == ""); PEGASUS_TEST_ASSERT(t[0] == '\0'); PEGASUS_TEST_ASSERT(u.size() == 0); PEGASUS_TEST_ASSERT(u == ""); PEGASUS_TEST_ASSERT(u[0] == '\0'); PEGASUS_TEST_ASSERT(s.size() == 0); PEGASUS_TEST_ASSERT(s == ""); PEGASUS_TEST_ASSERT(s[0] == '\0'); } // c_str() { String s("abc"); String t("abc"); String u("def"); String v; String w(""); PEGASUS_TEST_ASSERT(s == "abc"); PEGASUS_TEST_ASSERT(t == "abc"); PEGASUS_TEST_ASSERT(u == "def"); PEGASUS_TEST_ASSERT(s == t); PEGASUS_TEST_ASSERT(s != u); PEGASUS_TEST_ASSERT(v == ""); PEGASUS_TEST_ASSERT(v[0] == '\0'); PEGASUS_TEST_ASSERT(v[0] == '\0'); PEGASUS_TEST_ASSERT(w.size() == 0); PEGASUS_TEST_ASSERT(w[0] == '\0'); PEGASUS_TEST_ASSERT(w[0] == '\0'); } // set(size_t, char) { String s("abcdefghijklmnopqrstuvwxyz"); for (int i = 0; i < 26; i++) s[i] = toupper(s[i]); PEGASUS_TEST_ASSERT(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } // equal(const String&) { String t("abc"); String u("abc"); String v("def"); String w("defg"); String x(""); String y(""); PEGASUS_TEST_ASSERT(String::equal(t, t)); PEGASUS_TEST_ASSERT(String::equal(u, u)); PEGASUS_TEST_ASSERT(String::equal(v, v)); PEGASUS_TEST_ASSERT(String::equal(w, w)); PEGASUS_TEST_ASSERT(String::equal(x, x)); PEGASUS_TEST_ASSERT(String::equal(y, y)); PEGASUS_TEST_ASSERT(String::equal(t, u)); PEGASUS_TEST_ASSERT(String::equal(u, t)); PEGASUS_TEST_ASSERT(!String::equal(t, v)); PEGASUS_TEST_ASSERT(!String::equal(t, w)); PEGASUS_TEST_ASSERT(!String::equal(t, x)); PEGASUS_TEST_ASSERT(!String::equal(t, y)); PEGASUS_TEST_ASSERT(!String::equal(v, t)); PEGASUS_TEST_ASSERT(!String::equal(w, t)); PEGASUS_TEST_ASSERT(!String::equal(x, t)); PEGASUS_TEST_ASSERT(!String::equal(y, t)); PEGASUS_TEST_ASSERT(!String::equal(v, w)); PEGASUS_TEST_ASSERT(!String::equal(w, v)); PEGASUS_TEST_ASSERT(String::equal(x, y)); PEGASUS_TEST_ASSERT(String::equal(y, x)); } // equal(const char*) { String t("abc"); String u("abc"); String v("def"); String w("defg"); String x(""); String y(""); PEGASUS_TEST_ASSERT(String::equal(t, "abc")); PEGASUS_TEST_ASSERT(String::equal(u, "abc")); PEGASUS_TEST_ASSERT(String::equal(v, "def")); PEGASUS_TEST_ASSERT(String::equal(w, "defg")); PEGASUS_TEST_ASSERT(String::equal(x, "")); PEGASUS_TEST_ASSERT(String::equal(y, "")); PEGASUS_TEST_ASSERT(String::equal(t, "abc")); PEGASUS_TEST_ASSERT(String::equal(u, "abc")); PEGASUS_TEST_ASSERT(!String::equal(t, "def")); PEGASUS_TEST_ASSERT(!String::equal(t, "defg")); PEGASUS_TEST_ASSERT(!String::equal(t, "")); PEGASUS_TEST_ASSERT(!String::equal(t, "")); PEGASUS_TEST_ASSERT(!String::equal(v, "abc")); PEGASUS_TEST_ASSERT(!String::equal(w, "abc")); PEGASUS_TEST_ASSERT(!String::equal(x, "abc")); PEGASUS_TEST_ASSERT(!String::equal(y, "abc")); PEGASUS_TEST_ASSERT(!String::equal(v, "defg")); PEGASUS_TEST_ASSERT(!String::equal(w, "def")); PEGASUS_TEST_ASSERT(String::equal(x, "")); PEGASUS_TEST_ASSERT(String::equal(y, "")); } // equali() { String s("abc"); String t("abC"); String u("ABC"); String v("xyz"); String w(""); String x(""); PEGASUS_TEST_ASSERT(String::equalNoCase(s, t)); PEGASUS_TEST_ASSERT(String::equalNoCase(s, u)); PEGASUS_TEST_ASSERT(!String::equalNoCase(s, v)); PEGASUS_TEST_ASSERT(String::equalNoCase(w, x)); PEGASUS_TEST_ASSERT(!String::equalNoCase(w, s)); PEGASUS_TEST_ASSERT(!String::equalNoCase(w, t)); PEGASUS_TEST_ASSERT(!String::equalNoCase(w, v)); } { String t; const char MESSAGE[] = "hello"; const size_t LENGTH = sizeof(MESSAGE) - 1; String s = String(MESSAGE); t = s; String u = String(t); PEGASUS_TEST_ASSERT(t.size() == LENGTH); PEGASUS_TEST_ASSERT(t == MESSAGE); PEGASUS_TEST_ASSERT(s.size() == LENGTH); PEGASUS_TEST_ASSERT(s == MESSAGE); PEGASUS_TEST_ASSERT(u.size() == LENGTH); PEGASUS_TEST_ASSERT(u == MESSAGE); PEGASUS_TEST_ASSERT(t[0] == 'h'); PEGASUS_TEST_ASSERT(t[1] == 'e'); PEGASUS_TEST_ASSERT(t[2] == 'l'); PEGASUS_TEST_ASSERT(t[3] == 'l'); PEGASUS_TEST_ASSERT(t[4] == 'o'); PEGASUS_TEST_ASSERT(t[5] == '\0'); t.append(" world"); PEGASUS_TEST_ASSERT(t.size() == strlen("hello world")); PEGASUS_TEST_ASSERT(t == "hello world"); PEGASUS_TEST_ASSERT(s != "hello world"); PEGASUS_TEST_ASSERT(s == "hello"); PEGASUS_TEST_ASSERT(s.size() == strlen("hello")); t[0] = 'x'; PEGASUS_TEST_ASSERT(t == "xello world"); } // remove() { String s("abcXYZdefLMNOP"); s.remove(0,0); PEGASUS_TEST_ASSERT(s.size() == 14); PEGASUS_TEST_ASSERT(s == "abcXYZdefLMNOP"); s.remove(0, 3); PEGASUS_TEST_ASSERT(s.size() == 11); PEGASUS_TEST_ASSERT(s == "XYZdefLMNOP"); s.remove(3, 3); PEGASUS_TEST_ASSERT(s.size() == 8); PEGASUS_TEST_ASSERT(s == "XYZLMNOP"); s.remove(7, 1); PEGASUS_TEST_ASSERT(s.size() == 7); PEGASUS_TEST_ASSERT(s == "XYZLMNO"); s.remove(0, 1); PEGASUS_TEST_ASSERT(s.size() == 6); PEGASUS_TEST_ASSERT(s == "YZLMNO"); s.remove(2, PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(s.size() == 2); PEGASUS_TEST_ASSERT(s == "YZ"); s.remove(2, 0); PEGASUS_TEST_ASSERT(s.size() == 2); PEGASUS_TEST_ASSERT(s == "YZ"); s.remove(1, 1); PEGASUS_TEST_ASSERT(s.size() == 1); PEGASUS_TEST_ASSERT(s == "Y"); s.remove(0, 1); PEGASUS_TEST_ASSERT(s.size() == 0); PEGASUS_TEST_ASSERT(s == ""); PEGASUS_TEST_ASSERT(s[0] == '\0'); s.remove(0,0); PEGASUS_TEST_ASSERT(s.size() == 0); PEGASUS_TEST_ASSERT(s == ""); PEGASUS_TEST_ASSERT(s[0] == '\0'); } // subString() { String s("one two three"); PEGASUS_TEST_ASSERT(s.subString(0) == "one two three"); PEGASUS_TEST_ASSERT(s.subString(0, 3) == "one"); PEGASUS_TEST_ASSERT(s.subString(4, 3) == "two"); PEGASUS_TEST_ASSERT(s.subString(8, 5) == "three"); PEGASUS_TEST_ASSERT(s.subString(0, 0) == ""); PEGASUS_TEST_ASSERT(s.subString(13, 0) == ""); } // Overflow bool caught_bad_alloc = false; try { String s("junk", Uint32(0xFFFFFFFF)); } catch(...) { caught_bad_alloc = true; } PEGASUS_TEST_ASSERT(caught_bad_alloc); // Added to test funtionality of String(const String& str, Uint32 n) // for memory overflow. Boolean caughtBadAlloc = false; try { String s("abc", 0xFFFF0000); //to check for alloc } catch(const PEGASUS_STD(bad_alloc)&) { caughtBadAlloc = true; } // Added to test funtionality of // void reserveCapacity(Uint32 capacity) for memory overflow. caughtBadAlloc = false; try { String s; s.reserveCapacity(0xFFFF0000); //to check for _reserve } catch (const PEGASUS_STD(bad_alloc)&) { caughtBadAlloc = true; } PEGASUS_TEST_ASSERT(caughtBadAlloc); // Added to test funtionality of // String& append(const char* str, Uint32 size) for memory overflow. caughtBadAlloc = false; try { String s; s.append("xxx", 0xFFFF0000); //to check for _reserve } catch (const PEGASUS_STD(bad_alloc)&) { caughtBadAlloc = true; } PEGASUS_TEST_ASSERT(caughtBadAlloc); // Added to test funtionality of // String& append(const Char16* str, Uint32 n) for memory overflow. caughtBadAlloc = false; try { String s; s.append((Char16 *)"xxx", 0xFFFF0000); //to check for _reserve } catch (const PEGASUS_STD(bad_alloc)&) { caughtBadAlloc = true; } PEGASUS_TEST_ASSERT(caughtBadAlloc); // Added to test funtionality of // String& assign(const char* str, Uint32 n) for memory overflow. caughtBadAlloc = false; try { String s; s.assign("xxx", 0xFFFF0000); //to check for alloc } catch (const PEGASUS_STD(bad_alloc)&) { caughtBadAlloc = true; } PEGASUS_TEST_ASSERT(caughtBadAlloc); // Added to test funtionality of // String& assign(const Char16* str, Uint32 n) for memory overflow. caughtBadAlloc = false; try { String s; s.assign((Char16 *)"xxx", 0xFFFF0000); //to check for alloc } catch (const PEGASUS_STD(bad_alloc)&) { caughtBadAlloc = true; } PEGASUS_TEST_ASSERT(caughtBadAlloc); // Tests for the dump of a bad strings. // 40 good chars, bad char, 10 trailing chars. // Testing the full range of printed data. caughtBadAlloc = false; try { String s1("1234567890123456789012345678901234567890""\xFF""1234567890"); } catch ( Exception& ex ) { caughtBadAlloc = true; PEGASUS_TEST_ASSERT( strstr((const char*)ex.getMessage().getCString(), ": 1234567890123456789012345678901234567890" " 0xFF 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30") != 0); } PEGASUS_TEST_ASSERT(caughtBadAlloc); // 7 good chars, bad char, 7 trailing chars. // Testing reduced number of chars arround the bad char. caughtBadAlloc = false; try { String s1("0123456""\xAA""0123456"); } catch ( Exception& ex ) { caughtBadAlloc = true; PEGASUS_TEST_ASSERT( strstr((const char*)ex.getMessage().getCString(), ": 0123456 0xAA 0x30 0x31 0x32 0x33 0x34 0x35 0x36") != 0); } PEGASUS_TEST_ASSERT(caughtBadAlloc); // No good chars, bad char , 20 trailing chars // Testing no good chars, bad char at beginning, // more trailing chars available then printed. caughtBadAlloc = false; try { String s1("\xDD""0123456789012345679"); } catch ( Exception& ex ) { caughtBadAlloc = true; PEGASUS_TEST_ASSERT( strstr((const char*)ex.getMessage().getCString(), ": 0xDD 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39") != 0); } PEGASUS_TEST_ASSERT(caughtBadAlloc); // 50 good chars ( more the printed ), bad char as last char, // no trailing chars. caughtBadAlloc = false; try { String s1("AAAAAAAAAA0123456789012345678901234567890123456789""\xBB"); } catch ( Exception& ex ) { caughtBadAlloc = true; PEGASUS_TEST_ASSERT( strstr((const char*)ex.getMessage().getCString(), ": 0123456789012345678901234567890123456789 0xBB") != 0); } PEGASUS_TEST_ASSERT(caughtBadAlloc); // no good chars, bad char as the only char, no trailing chars. caughtBadAlloc = false; try { String s1("\x80"); } catch ( Exception& ex ) { caughtBadAlloc = true; PEGASUS_TEST_ASSERT( strstr((const char*)ex.getMessage().getCString(),": 0x80") != 0); } PEGASUS_TEST_ASSERT(caughtBadAlloc); cout << argv[0] << " +++++ passed all tests" << endl; char* p = (char*)operator new(88888); operator delete(p); return 0; }
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; }
String System::getEffectiveUserName() { #if (_MSC_VER >= 1300) || defined(PEGASUS_WINDOWS_SDK_HOME) //Bug 3076 fix wchar_t fullUserName[UNLEN+1]; DWORD userNameSize = sizeof(fullUserName)/sizeof(fullUserName[0]); wchar_t computerName[MAX_COMPUTERNAME_LENGTH+1]; DWORD computerNameSize = sizeof(computerName)/sizeof(computerName[0]); wchar_t userName[UNLEN+1]; wchar_t userDomain[UNLEN+1]; String userId; if (!GetUserNameExW(NameSamCompatible, fullUserName, &userNameSize)) { return String(); } wchar_t* index = wcschr(fullUserName, '\\'); *index = 0; wcscpy(userDomain, fullUserName); wcscpy(userName, index + 1); //The above function will return the system name as the domain if //the user is not on a real domain. Strip this out so that the rest of //our windows user functions work. What if the system name and the domain //name are the same? GetComputerNameW(computerName, &computerNameSize); if (wcscmp(computerName, userDomain) != 0) { //userId.append(userDomain); Uint32 n = (Uint32)wcslen(userDomain); for (unsigned long i = 0; i < n; i++) { userId.append(Char16(userDomain[i])); } userId.append("\\"); //userId.append(userName); n = (Uint32)wcslen(userName); for (unsigned long i = 0; i < n; i++) { userId.append(Char16(userName[i])); } } else { //userId.append(userName); Uint32 n = (Uint32)wcslen(userName); for (unsigned long i = 0; i < n; i++) { userId.append(Char16(userName[i])); } } return userId; #else //original getEffectiveUserName function int retcode = 0; // UNLEN (256) is the limit, not including null wchar_t pUserName[256+1] = {0}; DWORD nSize = sizeof(pUserName)/sizeof(pUserName[0]); retcode = GetUserNameW(pUserName, &nSize); if (retcode == 0) { // zero is failure return String(); } String userId; Uint32 n = wcslen(pUserName); for (unsigned long i = 0; i < n; i++) { userId.append(Char16(pUserName[i])); } return userId; #endif }
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"); }