int main(void){ wchar_t dest[11]; wchar_t dest2[11]; plan(9); ok(SUCCEEDED(StringCchCopyNW(dest, 11, L"test", 4)), "Copy entire string."); is_wstring(L"test", dest, "Result of copying entire string."); ok(SUCCEEDED(StringCchCopyNW(dest2, 11, dest, 11)), "Copy from buffer with additional capacity."); is_wstring(L"test", dest2, "Result of copying from buffer with additional capacity."); ok(SUCCEEDED(StringCchCopyNW(dest, 11, L"", 1)), "Copy empty string."); is_wstring(L"", dest, "Result of copying empty string."); ok(StringCchCopyNW(dest, 11, L"longer string", 12) == STRSAFE_E_INSUFFICIENT_BUFFER, "Copy a string that is too long."); is_wstring(L"longer str", dest, "Result of copying a string that is too long."); ok(StringCchCopyNW(dest, 0, L"test", 4) == STRSAFE_E_INVALID_PARAMETER, "Make sure error is thrown if cchDest is zero."); return 0; }
int main(void){ wchar_t dest[11]; plan(7); ok(SUCCEEDED(StringCchCopyW(dest, 11, L"test")), "Copy short string."); is_wstring(L"test", dest, "Result of copying short string."); ok(SUCCEEDED(StringCchCopyW(dest, 11, L"")), "Copy empty string."); is_wstring(L"", dest, "Result of copying empty string."); ok(StringCchCopyW(dest, 11, L"longer string") == STRSAFE_E_INSUFFICIENT_BUFFER, "Copy a string that is too long."); is_wstring(L"longer str", dest, "Result of copying a string that is too long."); ok(StringCchCopyW(dest, 0, L"test") == STRSAFE_E_INVALID_PARAMETER, "Make sure error is thrown if cchDest is zero."); return 0; }
void testDestEnd(){ wchar_t dest[11]; wchar_t * destEnd; diag("Test calculation of destEnd."); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), &destEnd, NULL, 0, L"Data")), "Test calculation of destEnd " "while printing short string."); is_wstring(L"Data", dest, "Result of printing short string."); ok(destEnd == &dest[4], "Value of destEnd after printing short string."); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), &destEnd, NULL, 0, L"")), "Test calculation of destEnd " "while printing empty string."); is_wstring(L"", dest, "Result of printing empty string."); ok(destEnd == &dest[0], "Value of destEnd after printing empty string."); ok(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), &destEnd, NULL, 0, L"longer %ls", L"string") == STRSAFE_E_INSUFFICIENT_BUFFER, "Test calculation of destEnd " "while printing a too long string."); is_wstring(L"longer str", dest, "Result of printing a too long string."); ok(destEnd == &dest[10], "Value of destEnd after printing a too long string."); }
void testRemaining(){ wchar_t dest[11]; size_t remaining; diag("Test calculation of remaining space."); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, &remaining, 0, L"STR")), "Test calculation of remaining space " "while printing short string."); is_wstring(L"STR", dest, "Result of printing short string."); is_int(8 * sizeof(wchar_t), remaining, "Number of remaining characters after printing short string."); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, &remaining, 0, L"")), "Test calculation of remaining space " "while printing empty string."); is_wstring(L"", dest, "Result of printing empty string."); is_int(11 * sizeof(wchar_t), remaining, "Number of remaining characters after printing empty string."); ok(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, &remaining, 0, L"too long string") == STRSAFE_E_INSUFFICIENT_BUFFER, "Test calculation of remaining space " "while printing a too long string."); is_wstring(L"too long s", dest, "Result of printing a too long string."); is_int(1 * sizeof(wchar_t), remaining, "Number of remaining characters after printing " "a too long string."); }
int main(void){ wchar_t dest[11]; plan(31); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, NULL, 0, L"test")), "Print short string without any extended functionality."); is_wstring(L"test", dest, "Result of printing short string."); testDestEnd(); testRemaining(); testFlags(); return 0; }
/// /// write a wide string to a wostream /// std::wostream& TypeVar::_write_wstring(std::wostream& os) const { assert(is_wstring()); os << '\''; for (const wchar_t* s = (*boost::get<wstring_t>(_var).ps).c_str(); *s; ++s) switch (*s) { case '\b' : os << L"\\b"; break; case '\r' : os << L"\\r"; break; case '\n' : os << L"\\n"; break; case '\f' : os << L"\\f"; break; case '\t' : os << L"\\t"; break; case '\\' : os << L"\\\\"; break; case '\'' : os << L"\\'"; break; default : if (*s < ' ') os << "0" << std::oct << std::setw(3) << std::setfill(L'0') << int(*s); else os << *s; } os << '\''; return os; }
/// /// write a wide string to an ostream /// std::ostream& TypeVar::_write_wstring(std::ostream& os) const { assert(is_wstring()); //os << '"'; for (const wchar_t* s = (*boost::get<wstring_t>(_var).ps).c_str(); *s; ++s) switch (*s) { case L'\b' : os << L"\\b"; break; case L'\r' : os << L"\\r"; break; case L'\n' : os << L"\\n"; break; case L'\f' : os << L"\\f"; break; case L'\t' : os << L"\\t"; break; case L'\\' : os << L"\\\\"; break; case L'\"' : os << L"\\\""; break; //case L'/' : os << L"\\/"; break; default : if (std::iswcntrl(*s)) os << L"0" << std::oct << std::setw(3) << std::setfill('0') << int(*s); else os << *s; } //os << '"'; return os; }
int main(void){ wchar_t dest[11] = L"test"; wchar_t empty[10] = L""; plan(12); ok(SUCCEEDED(StringCbCatW(dest, 11 * sizeof(wchar_t), L"TEST")), "Concatenate two short strings."); is_wstring(L"testTEST", dest, "Result of concatenating short strings."); dest[4] = '\0'; /* Reset dest to "test". */ ok(SUCCEEDED(StringCbCatW(dest, 11 * sizeof(wchar_t), L"")), "Concatenate with empty source."); is_wstring(L"test", dest, "Result of concatenating with empty source."); ok(SUCCEEDED(StringCbCatW(empty, 10 * sizeof(wchar_t), L"test")), "Concatenate with empty destination."); is_wstring(L"test", empty, "Result of concatenating with empty destination."); ok(StringCbCatW(dest, 11 * sizeof(wchar_t), L"longer string") == STRSAFE_E_INSUFFICIENT_BUFFER, "Concatenate two strings that are too long."); is_wstring(L"testlonger", dest, "Result of concatenating two strings that are too long."); ok(StringCbCatW(dest, 11 * sizeof(wchar_t), L"test") == STRSAFE_E_INSUFFICIENT_BUFFER, "Concatenate to already full destination."); is_wstring(L"testlonger", dest, "Make sure destination was not modified."); ok(StringCbCatW(dest, 0 * sizeof(wchar_t), L"test") == STRSAFE_E_INVALID_PARAMETER, "Make sure error is thrown if cchDest is zero."); is_wstring(L"testlonger", dest, "Make sure destination was not modified."); return 0; }
void testFlags(){ wchar_t dest[11]; wchar_t * wanted; diag("Test the STRSAFE_IGNORE_NULLS flag."); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, NULL, STRSAFE_IGNORE_NULLS, NULL)), "Test printing a NULL string."); is_wstring(L"", dest, "Result of printing a NULL string."); diag("Test the STRSAFE_FILL_BEHIND_NULL flag."); ok(SUCCEEDED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, NULL, STRSAFE_FILL_BEHIND_NULL | '@', L"testing")), "Test filling with '@' behind null termination."); is_wstring(L"testing", dest, "Result of printing and filling behind null termination."); wanted = malloc(3 * sizeof(wchar_t)); if(wanted == NULL){ bail("Memory allocation failed."); } memset(wanted, '@', 3 * sizeof(wchar_t)); ok(memcmp(&dest[8], wanted, 3 * sizeof(wchar_t)) == 0, "Correct data filled after null termination."); free(wanted); diag("Test the STRSAFE_FILL_ON_FAILURE flag."); ok(FAILED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, NULL, STRSAFE_FILL_ON_FAILURE | '@', L"too much data")), "Test filling with '@' on failure."); wanted = malloc(11 * sizeof(wchar_t)); if(wanted == NULL){ bail("Memory allocation failed."); } memset(wanted, '@', 10 * sizeof(wchar_t)); wanted[10] = L'\0'; ok(memcmp(dest, wanted, 11 * sizeof(wchar_t)) == 0, "Result of filling with '@' on failure."); free(wanted); diag("Test the STRSAFE_NULL_ON_FAILURE flag."); ok(FAILED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, NULL, STRSAFE_NULL_ON_FAILURE, L"Also too much")), "Test nulling string on failure."); is_wstring(L"", dest, "Result when nulling string on failure."); diag("Test the STRSAFE_NO_TRUNCATION flag."); ok(FAILED(StringCbPrintfExW(dest, 11 * sizeof(wchar_t), NULL, NULL, STRSAFE_NO_TRUNCATION, L"Won't fit in dest")), "Test printing with truncating disabled."); is_wstring(L"", dest, "Result after printing with truncating disabled."); }
/// is var a string type? bool is_string_type() const { return is_string() || is_wstring(); }
int main(void){ wchar_t dest[11] = L"test"; wchar_t dest2[11] = L"TEST"; wchar_t empty[10] = L""; plan(16); ok(SUCCEEDED(StringCbCatNW(dest, 11 * sizeof(wchar_t), L"test", 4 * sizeof(wchar_t))), "Concatenate entire strings."); is_wstring(L"testtest", dest, "Result of concatenating entire strings."); dest[4] = '\0'; /* Reset dest to "test". */ ok(SUCCEEDED(StringCbCatNW(dest, 11 * sizeof(wchar_t), L"", 1 * sizeof(wchar_t))), "Concatenate with empty source."); is_wstring(L"test", dest, "Result of concatenating with empty source."); ok(SUCCEEDED(StringCbCatNW(empty, 10 * sizeof(wchar_t), L"test", 4 * sizeof(wchar_t))), "Concatenate with empty destination."); is_wstring(L"test", empty, "Result of concatenating with empty destination."); ok(SUCCEEDED(StringCbCatNW(dest2, 11 * sizeof(wchar_t), dest, 11 * sizeof(wchar_t))), "Concatenate two buffers with additional capacity."); is_wstring(L"TESTtest", dest2, "Result of concatenating buffers with additional capacity."); ok(StringCbCatNW(dest, 11 * sizeof(wchar_t), L"longer string", 12 * sizeof(wchar_t)) == STRSAFE_E_INSUFFICIENT_BUFFER, "Concatenate a string that is too long."); is_wstring(L"testlonger", dest, "Result of concatenating two strings that are too long."); ok(SUCCEEDED(StringCbCatNW(dest2, 11 * sizeof(wchar_t), dest, 2 * sizeof(wchar_t))), "Concatenate a few characters from a longer string."); is_wstring(L"TESTtestte", dest2, "Result of concatenating a few characters."); ok(StringCbCatNW(dest, 11 * sizeof(wchar_t), L"test", 4 * sizeof(wchar_t)) == STRSAFE_E_INSUFFICIENT_BUFFER, "Concatenate to already full destination."); is_wstring(L"testlonger", dest, "Make sure destination was not modified."); ok(StringCbCatNW(dest, 0 * sizeof(wchar_t), L"test", 4 * sizeof(wchar_t)) == STRSAFE_E_INVALID_PARAMETER, "Make sure error is thrown if cchDest is zero."); is_wstring(L"testlonger", dest, "Make sure destination was not modified."); return 0; }