For debugging I sometimes use .ascii().data() to get a printable string, not sure if this is a good thing to use in a test though. This returns a C-style string which you can then use with EXPECT_STREQ, etc.
Add:
#include "wtf/testing/WTFTestHelpers.h"
I poked at this a bit. It's very interesting because this works:
String testString("Hello");
std::cout << testString << "\n"; // Prints "Hello."
but this does not:
std::cout << ::testing::PrintToString(testString) << "\n"; // Prints 8-byte object <XX-XX XX-XX XX-XX XX-XX>
I asked around, and it turns out this is due to an ODR violation. Since WTF::String's operator<< isn't defined in the same header as WTF::String, there are two definitions of template<> DefaultPrintNonContainerTo(const WTF::String&, std::ostream*):
1. For tests that forget to #include "WTFTestHelpers.h", the definition of DefaultPrintNonContainerTo() uses gtest's fallback operator<<.
2. For tests that do include it, the definition uses the operator<< defined in WTFTestHelpers.h.
Since ODR is undefined behavior, it works sometimes and doesn't work other times. In this case, I think the solution is to define operator<< / PrintTo in the same header as WTF::String.
Daniel
I poked at this a bit. It's very interesting because this works:
String testString("Hello");
std::cout << testString << "\n"; // Prints "Hello."
but this does not:
std::cout << ::testing::PrintToString(testString) << "\n"; // Prints 8-byte object <XX-XX XX-XX XX-XX XX-XX>
I asked around, and it turns out this is due to an ODR violation. Since WTF::String's operator<< isn't defined in the same header as WTF::String, there are two definitions of template<> DefaultPrintNonContainerTo(const WTF::String&, std::ostream*):
1. For tests that forget to #include "WTFTestHelpers.h", the definition of DefaultPrintNonContainerTo() uses gtest's fallback operator<<.
2. For tests that do include it, the definition uses the operator<< defined in WTFTestHelpers.h.Since ODR is undefined behavior, it works sometimes and doesn't work other times. In this case, I think the solution is to define operator<< / PrintTo in the same header as WTF::String.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.