Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/tests/test_CStr.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 "ps/CStr.h" | #include "ps/CStr.h" | ||||
class TestCStr : public CxxTest::TestSuite | class TestCStr : public CxxTest::TestSuite | ||||
{ | { | ||||
public: | public: | ||||
void test_utf8_utf16_conversion() | void test_utf8_utf16_conversion() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
void test_parse() | void test_parse() | ||||
{ | { | ||||
// Parsing should be independent of locale ("," vs "."), | // Parsing should be independent of locale ("," vs "."), | ||||
// because GTK+ can change the locale when we're running Atlas. | // because GTK+ can change the locale when we're running Atlas. | ||||
// (If the host system doesn't have the locale we're using for this test | // (If the host system doesn't have the locale we're using for this test | ||||
// then it'll just stick with the default, which is fine) | // then it'll just stick with the default, which is fine) | ||||
char* old = setlocale(LC_NUMERIC, "fr_FR.UTF-8"); | ScopedLocale(LC_NUMERIC, "en_US.UTF-8"); | ||||
CStr8 str1("1.234"); | CStr8 str1("1.234"); | ||||
TS_ASSERT_DELTA(str1.ToFloat(), 1.234f, 0.0001f); | TS_ASSERT_DELTA(str1.ToFloat(), 1.234f, 0.0001f); | ||||
TS_ASSERT_DELTA(str1.ToDouble(), 1.234, 0.0001); | TS_ASSERT_DELTA(str1.ToDouble(), 1.234, 0.0001); | ||||
TS_ASSERT_EQUALS(str1.ToInt(), 1); | TS_ASSERT_EQUALS(str1.ToInt(), 1); | ||||
TS_ASSERT_EQUALS(str1.ToUInt(), 1u); | TS_ASSERT_EQUALS(str1.ToUInt(), 1u); | ||||
TS_ASSERT_EQUALS(str1.ToLong(), 1); | TS_ASSERT_EQUALS(str1.ToLong(), 1); | ||||
TS_ASSERT_EQUALS(str1.ToULong(), 1u); | TS_ASSERT_EQUALS(str1.ToULong(), 1u); | ||||
CStr8 str2("bogus"); | CStr8 str2("bogus"); | ||||
TS_ASSERT_EQUALS(str2.ToFloat(), 0.0f); | TS_ASSERT_EQUALS(str2.ToFloat(), 0.0f); | ||||
TS_ASSERT_EQUALS(str2.ToDouble(), 0.0); | TS_ASSERT_EQUALS(str2.ToDouble(), 0.0); | ||||
TS_ASSERT_EQUALS(str2.ToInt(), 0); | TS_ASSERT_EQUALS(str2.ToInt(), 0); | ||||
TS_ASSERT_EQUALS(str2.ToUInt(), 0u); | TS_ASSERT_EQUALS(str2.ToUInt(), 0u); | ||||
TS_ASSERT_EQUALS(str2.ToLong(), 0); | TS_ASSERT_EQUALS(str2.ToLong(), 0); | ||||
TS_ASSERT_EQUALS(str2.ToULong(), 0u); | TS_ASSERT_EQUALS(str2.ToULong(), 0u); | ||||
CStr8 str3("3bogus"); | CStr8 str3("3bogus"); | ||||
TS_ASSERT_EQUALS(str3.ToFloat(), 3.0f); | TS_ASSERT_EQUALS(str3.ToFloat(), 3.0f); | ||||
TS_ASSERT_EQUALS(str3.ToDouble(), 3.0); | TS_ASSERT_EQUALS(str3.ToDouble(), 3.0); | ||||
TS_ASSERT_EQUALS(str3.ToInt(), 3); | TS_ASSERT_EQUALS(str3.ToInt(), 3); | ||||
TS_ASSERT_EQUALS(str3.ToUInt(), 3u); | TS_ASSERT_EQUALS(str3.ToUInt(), 3u); | ||||
TS_ASSERT_EQUALS(str3.ToLong(), 3); | TS_ASSERT_EQUALS(str3.ToLong(), 3); | ||||
TS_ASSERT_EQUALS(str3.ToULong(), 3u); | TS_ASSERT_EQUALS(str3.ToULong(), 3u); | ||||
setlocale(LC_NUMERIC, old); | |||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator