Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/tests/test_cppformat.h
Show All 10 Lines | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "lib/self_test.h" | #include "lib/self_test.h" | ||||
#include "lib/scoped_locale.h" | |||||
#include "third_party/cppformat/format.h" | #include "third_party/cppformat/format.h" | ||||
class TestCppformat : public CxxTest::TestSuite | class TestCppformat : public CxxTest::TestSuite | ||||
{ | { | ||||
public: | public: | ||||
void test_basic() | void test_basic() | ||||
{ | { | ||||
// Make test behave independent of current host locale | // Make test behave independent of current host locale | ||||
char* old = setlocale(LC_ALL, "en_US.UTF-8"); | ScopedLocale(LC_ALL, "en_US.UTF-8"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("abc"), "abc"); | TS_ASSERT_EQUALS(fmt::sprintf("abc"), "abc"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("%d", 123), "123"); | TS_ASSERT_EQUALS(fmt::sprintf("%d", 123), "123"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("%d", (int64_t)123), "123"); | TS_ASSERT_EQUALS(fmt::sprintf("%d", (int64_t)123), "123"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("%i", 123), "123"); | TS_ASSERT_EQUALS(fmt::sprintf("%i", 123), "123"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("%04x", 123), "007b"); | TS_ASSERT_EQUALS(fmt::sprintf("%04x", 123), "007b"); | ||||
Show All 15 Lines | void test_basic() | ||||
TS_ASSERT_EQUALS(fmt::sprintf("T%sT", "abc"), "TabcT"); | TS_ASSERT_EQUALS(fmt::sprintf("T%sT", "abc"), "TabcT"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("T%sT", std::string("abc")), "TabcT"); | TS_ASSERT_EQUALS(fmt::sprintf("T%sT", std::string("abc")), "TabcT"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("T%sT", CStr("abc")), "TabcT"); | TS_ASSERT_EQUALS(fmt::sprintf("T%sT", CStr("abc")), "TabcT"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("T%sT", (const char*)NULL), "T(null)T"); | TS_ASSERT_EQUALS(fmt::sprintf("T%sT", (const char*)NULL), "T(null)T"); | ||||
TS_ASSERT_EQUALS(fmt::sprintf("T%pT", (void*)0x1234), "T0x1234T"); | TS_ASSERT_EQUALS(fmt::sprintf("T%pT", (void*)0x1234), "T0x1234T"); | ||||
setlocale(LC_ALL, old); | |||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator