Commit 910dec5e authored by Victor Zverovich's avatar Victor Zverovich

Fix 'l' specifier test.

parent 028d12da
...@@ -300,12 +300,16 @@ template <typename T, typename U> ...@@ -300,12 +300,16 @@ template <typename T, typename U>
std::string sprintf_int(std::string format, U value) { std::string sprintf_int(std::string format, U value) {
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
char type = format[format.size() - 1]; char type = format[format.size() - 1];
if (type == 'd' || type == 'i') { if (sizeof(T) < sizeof(U)) {
typedef typename MakeSigned<T>::Type Signed; if (type == 'd' || type == 'i') {
safe_sprintf(buffer, format.c_str(), static_cast<Signed>(value)); typedef typename MakeSigned<T>::Type Signed;
safe_sprintf(buffer, format.c_str(), static_cast<Signed>(value));
} else {
typedef typename fmt::internal::MakeUnsigned<T>::Type Unsigned;
safe_sprintf(buffer, format.c_str(), static_cast<Unsigned>(value));
}
} else { } else {
typedef typename fmt::internal::MakeUnsigned<T>::Type Unsigned; safe_sprintf(buffer, format.c_str(), value);
safe_sprintf(buffer, format.c_str(), static_cast<Unsigned>(value));
} }
return buffer; return buffer;
} }
...@@ -348,11 +352,11 @@ TEST(PrintfTest, Length) { ...@@ -348,11 +352,11 @@ TEST(PrintfTest, Length) {
TestLength<unsigned char>("hh"); TestLength<unsigned char>("hh");
TestLength<short>("h"); TestLength<short>("h");
TestLength<unsigned short>("h"); TestLength<unsigned short>("h");
EXPECT_EQ("-1", sprintf_int<unsigned char>("%hhd", UCHAR_MAX)); TestLength<long>("l");
EXPECT_EQ("255", sprintf_int<unsigned char>("%hhu", UCHAR_MAX));
//TestLength<long>("l");
//TestLength<unsigned long>("l"); //TestLength<unsigned long>("l");
// TODO: more tests // TODO: more tests
EXPECT_EQ("-1", sprintf_int<unsigned char>("%hhd", UCHAR_MAX));
EXPECT_EQ("255", sprintf_int<unsigned char>("%hhu", UCHAR_MAX));
} }
// TODO: test type specifier // TODO: test type specifier
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment