Пример #1
0
bool
test_valid()
{
  for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
    nsDependentCString str8(ValidStrings[i].m8);
    nsDependentString str16(ValidStrings[i].m16);

    if (!NS_ConvertUTF16toUTF8(str16).Equals(str8))
      return false;

    if (!NS_ConvertUTF8toUTF16(str8).Equals(str16))
      return false;

    nsCString tmp8("string ");
    AppendUTF16toUTF8(str16, tmp8);
    if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8))
      return false;

    nsString tmp16(NS_LITERAL_STRING("string "));
    AppendUTF8toUTF16(str8, tmp16);
    if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16))
      return false;

    if (CompareUTF8toUTF16(str8, str16) != 0)
      return false;
  }
  
  return true;
}
String16 jstringToString16(JNIEnv* env, jstring jstr) {
    const jchar* str = env->GetStringCritical(jstr, 0);
    String16 str16(reinterpret_cast<const char16_t*>(str),
                   env->GetStringLength(jstr));
    env->ReleaseStringCritical(jstr, str);
    return str16;
}
Пример #3
0
PRBool
test_basic()
{
  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) {
    nsDependentString str16(ValidStrings[i].m16);
    nsDependentCString str8(ValidStrings[i].m8);

    nsCOMPtr<nsIAtom> atom = do_GetAtom(str16);
    
    if (!atom->Equals(str16) || !atom->EqualsUTF8(str8))
      return PR_FALSE;

    nsString tmp16;
    nsCString tmp8;
    atom->ToString(tmp16);
    atom->ToUTF8String(tmp8);
    if (!str16.Equals(tmp16) || !str8.Equals(tmp8))
      return PR_FALSE;

    if (!nsDependentString(atom->GetUTF16String()).Equals(str16))
      return PR_FALSE;

    if (!nsAtomString(atom).Equals(str16) ||
        !nsDependentAtomString(atom).Equals(str16) ||
        !nsAtomCString(atom).Equals(str8))
      return PR_FALSE;
  }
  
  return PR_TRUE;
}
Пример #4
0
PRBool
test_valid()
{
  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) {
    nsDependentCString str8(ValidStrings[i].m8);
    nsDependentString str16(ValidStrings[i].m16);

    if (!NS_ConvertUTF16toUTF8(str16).Equals(str8))
      return PR_FALSE;

    if (!NS_ConvertUTF8toUTF16(str8).Equals(str16))
      return PR_FALSE;

    nsCString tmp8("string ");
    AppendUTF16toUTF8(str16, tmp8);
    if (!tmp8.Equals(NS_LITERAL_CSTRING("string ") + str8))
      return PR_FALSE;

    nsString tmp16(NS_LITERAL_STRING("string "));
    AppendUTF8toUTF16(str8, tmp16);
    if (!tmp16.Equals(NS_LITERAL_STRING("string ") + str16))
      return PR_FALSE;

    if (CompareUTF8toUTF16(str8, str16) != 0)
      return PR_FALSE;
  }
  
  return PR_TRUE;
}
Пример #5
0
/*
 * Convert an Internet host address given in network byte order
 * to string in standard numbers and dots notation.
 */
PJ_DEF(char*) pj_inet_ntoa(pj_in_addr inaddr)
{
	static char str8[PJ_INET_ADDRSTRLEN];
    TBuf<PJ_INET_ADDRSTRLEN> str16(0);

    /* (Symbian IP address is in host byte order) */
    TInetAddr temp_addr((TUint32)pj_ntohl(inaddr.s_addr), (TUint)0);
    temp_addr.Output(str16);
 
    return pj_unicode_to_ansi((const wchar_t*)str16.PtrZ(), str16.Length(),
			      str8, sizeof(str8));
}
Пример #6
0
TEST(UTF, Invalid8)
{
  for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
    nsDependentString str16(Invalid8Strings[i].m16);
    nsDependentCString str8(Invalid8Strings[i].m8);

    EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));

    nsString tmp16(NS_LITERAL_STRING("string "));
    AppendUTF8toUTF16(str8, tmp16);
    EXPECT_TRUE(tmp16.Equals(NS_LITERAL_STRING("string ") + str16));

    EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
  }
}
Пример #7
0
static Variant HHVM_METHOD(Transliterator, transliterate,
                           const String& str, int64_t begin, int64_t end) {
  FETCH_TRANS(data, this_);
  if (end < -1) {
    data->setError(U_ILLEGAL_ARGUMENT_ERROR,
                   "transliterator_transliterate: \"end\" argument should be "
                   "either non-negative or -1");
    return false;
  }
  if ((begin < 0) || ((end != -1) && (begin > end))) {
    data->setError(U_ILLEGAL_ARGUMENT_ERROR,
                   "transliterator_transliterate: \"start\" argument should be "
                   "non-negative and not bigger than \"end\" (if defined)");
    return false;
  }
  UErrorCode error = U_ZERO_ERROR;
  icu::UnicodeString str16(u16(str, error));
  if (U_FAILURE(error)) {
    data->setError(error, "String conversion of string to UTF-16 failed");
    return false;
  }
  if ((begin > str16.length()) || ((end != -1) && (end > str16.length()))) {
    data->setError(U_ILLEGAL_ARGUMENT_ERROR,
                   "transliterator_transliterate: Neither \"start\" nor the "
                   "\"end\" arguments can exceed the number of UTF-16 code "
                   "units (in this case, %d)", (int)str16.length());
    return false;
  }
  data->trans()->transliterate(str16, begin, (end < 0) ? str16.length() : end);

  error = U_ZERO_ERROR;
  String ret(u8(str16, error));
  if (U_FAILURE(error)) {
    data->setError(error, "String conversion of string to UTF-8 failed");
    return false;
  }
  data->clearError();
  return ret;
}
Пример #8
0
//Getting various information and security policy from the repository
//TInt 				CServerRepository::Get(TUint32 aId,T& aVal)
//TServerSetting* 	CServerRepository::GetSetting(TUint32 aId)
void CenrepSrvOOMTest::GetL()
	{
	TInt err=KErrNone;
	TInt keyInt=0;
	TServerSetting* srvsetting;
	//----------Getting the TInt(1-15)-----------------------------
	for (TInt i=1;i<=15;i++)
		{
		err=iServerRepo->Get(i,keyInt);
		//Remember the policy check is done at the session level
		TESTKErrNoneL(err);
		TESTL(i==keyInt);
		srvsetting=iServerRepo->GetSetting(i);
		TESTL(srvsetting->Key()==static_cast<TUint32>(i));
		}
	//---------Getting the TReal(16-19)---------------------------
	TReal keyValue;
	err=iServerRepo->Get(16,keyValue);
	TESTKErrNoneL(err);
	TESTL(keyValue==10.1010);
	srvsetting=iServerRepo->GetSetting(16);
	TESTL(srvsetting->Key()==16);

	err=iServerRepo->Get(19,keyValue);
	TESTKErrNoneL(err);
	TESTL(keyValue==13.1313);

	//----------Getting the String(20-23)-----------------------
	TBuf8<50> keyString;
	_LIT(KFourteen,"fourteen");
	err=iServerRepo->Get(20,keyString);
	TESTKErrNoneL(err);
	//Even ascii(8 bytes) are stored as 16 bytes!!!
	TPtr16 str16((TUint16*) keyString.Ptr(),keyString.Length()/2,keyString.Length()/2);
	TESTL(str16.Compare(KFourteen)==0);
	srvsetting=iServerRepo->GetSetting(20);
	TESTL(srvsetting->Key()==20);

	//---------Getting the String8(0x79)------------------------
	TBuf8<50> keyString8;
	_LIT8(KString8,"string8");
	err=iServerRepo->Get(0x79,keyString8);
	TESTKErrNoneL(err);
	TESTL(keyString8.Compare(KString8)==0);
	srvsetting=iServerRepo->GetSetting(0x79);
	TESTL(srvsetting->Key()==0x79);

	//---------Getting the binary(0x82)-------------------------
	TBuf8<50> keyBinary;
	_LIT8(KBinary8,"\x12\x34\xAB\xCD");
	err=iServerRepo->Get(0x82,keyBinary);
	TESTKErrNoneL(err);
	//temporarily added to solve coverage problem in WINSCW
#ifdef __EPOC32__
	TESTL(keyBinary.Compare(KBinary8)==0);
#endif
	srvsetting=iServerRepo->GetSetting(0x82);
	TESTL(srvsetting->Key()==0x82);

	//----------Getting individual policy-----------------------
	//Current Exe has caps AllFiles+WriteDeviceData+ReadDeviceData
	RThread currentThread;
	TSecurityPolicy secPolicy;
	//default policy
	secPolicy=iServerRepo->GetDefaultReadAccessPolicy();
	TESTL(secPolicy.CheckPolicy(currentThread)==1);
	secPolicy=iServerRepo->GetDefaultWriteAccessPolicy();
	TESTL(secPolicy.CheckPolicy(currentThread)==1);

	//check settings policies
	//0x2 int 2 1 cap_rd=CommDD cap_wr=WriteDeviceData
	//0x19 int 25 0 //defined in range policies with cap_rd=NetworkServices
	secPolicy=iServerRepo->GetReadAccessPolicy(2);
	TESTL(secPolicy.CheckPolicy(currentThread)==0);
	secPolicy=iServerRepo->GetWriteAccessPolicy(2);
	TESTL(secPolicy.CheckPolicy(currentThread)==1);
	secPolicy=iServerRepo->GetReadAccessPolicy(25);
	TESTL(secPolicy.CheckPolicy(currentThread)==0);

	}