Changed locale handling and added tests
This commit is contained in:
@@ -1626,9 +1626,6 @@ bool CCryEditApp::InitInstance()
|
||||
ReflectedVarInit::setupReflection(serializeContext);
|
||||
RegisterReflectedVarHandlers();
|
||||
|
||||
|
||||
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
|
||||
CreateSplashScreen();
|
||||
|
||||
// Register the application's document templates. Document templates
|
||||
|
||||
@@ -22,8 +22,6 @@ namespace AzQtComponents
|
||||
QApplication::setApplicationName("O3DE Tools Application");
|
||||
|
||||
AzQtComponents::PrepareQtPaths();
|
||||
|
||||
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
}
|
||||
|
||||
void AzQtApplication::InitializeDpiScaling()
|
||||
|
||||
@@ -134,8 +134,6 @@ int main(int argc, char **argv)
|
||||
QApplication::setOrganizationDomain("o3de.org");
|
||||
QApplication::setApplicationName("O3DEWidgetGallery");
|
||||
|
||||
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
|
||||
+52
-12
@@ -13,54 +13,94 @@
|
||||
|
||||
TEST(AzQtComponents, FloatToString_Truncate2Decimals)
|
||||
{
|
||||
QLocale testLocal(QLocale::English, QLocale::UnitedStates);
|
||||
QLocale testLocale(QLocale::English, QLocale::UnitedStates);
|
||||
|
||||
const bool showThousandsSeparator = false;
|
||||
const int numDecimalPlaces = 2;
|
||||
EXPECT_EQ(AzQtComponents::toString(0.1234, numDecimalPlaces, testLocal, showThousandsSeparator), "0.12");
|
||||
EXPECT_EQ(AzQtComponents::toString(0.1234, numDecimalPlaces, testLocale, showThousandsSeparator), "0.12");
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_AllZerosButOne)
|
||||
{
|
||||
QLocale testLocal(QLocale::English, QLocale::UnitedStates);
|
||||
QLocale testLocale(QLocale::English, QLocale::UnitedStates);
|
||||
|
||||
const bool showThousandsSeparator = false;
|
||||
int numDecimalPlaces = 2;
|
||||
EXPECT_EQ(AzQtComponents::toString(1.0000, numDecimalPlaces, testLocal, showThousandsSeparator), "1.0");
|
||||
EXPECT_EQ(AzQtComponents::toString(1.0000, numDecimalPlaces, testLocale, showThousandsSeparator), "1.0");
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_TruncateAllZerosButOne)
|
||||
{
|
||||
QLocale testLocal(QLocale::English, QLocale::UnitedStates);
|
||||
QLocale testLocale(QLocale::English, QLocale::UnitedStates);
|
||||
|
||||
const bool showThousandsSeparator = false;
|
||||
int numDecimalPlaces = 2;
|
||||
EXPECT_EQ(AzQtComponents::toString(1.0001, numDecimalPlaces, testLocal, showThousandsSeparator), "1.0");
|
||||
EXPECT_EQ(AzQtComponents::toString(1.0001, numDecimalPlaces, testLocale, showThousandsSeparator), "1.0");
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_TruncateNotRound)
|
||||
{
|
||||
QLocale testLocal(QLocale::English, QLocale::UnitedStates);
|
||||
QLocale testLocale(QLocale::English, QLocale::UnitedStates);
|
||||
|
||||
const bool showThousandsSeparator = false;
|
||||
int numDecimalPlaces = 3;
|
||||
EXPECT_EQ(AzQtComponents::toString(0.1236, numDecimalPlaces, testLocal, showThousandsSeparator), "0.123");
|
||||
EXPECT_EQ(AzQtComponents::toString(0.1236, numDecimalPlaces, testLocale, showThousandsSeparator), "0.123");
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_TruncateShowThousandsSeparatorTruncateNoRound)
|
||||
{
|
||||
QLocale testLocal(QLocale::English, QLocale::UnitedStates);
|
||||
QLocale testLocale(QLocale::English, QLocale::UnitedStates);
|
||||
|
||||
const bool showThousandsSeparator = true;
|
||||
int numDecimalPlaces = 3;
|
||||
EXPECT_EQ(AzQtComponents::toString(1000.1236, numDecimalPlaces, testLocal, showThousandsSeparator), "1,000.123");
|
||||
EXPECT_EQ(AzQtComponents::toString(1000.1236, numDecimalPlaces, testLocale, showThousandsSeparator), "1,000.123");
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_TruncateShowThousandsSeparatorOnlyOneDecimal)
|
||||
{
|
||||
QLocale testLocal(QLocale::English, QLocale::UnitedStates);
|
||||
QLocale testLocale(QLocale::English, QLocale::UnitedStates);
|
||||
|
||||
const bool showThousandsSeparator = true;
|
||||
int numDecimalPlaces = 2;
|
||||
EXPECT_EQ(AzQtComponents::toString(1000.000, numDecimalPlaces, testLocal, showThousandsSeparator), "1,000.0");
|
||||
EXPECT_EQ(AzQtComponents::toString(1000.000, numDecimalPlaces, testLocale, showThousandsSeparator), "1,000.0");
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_Truncate2DecimalsWithLocale)
|
||||
{
|
||||
QLocale testLocale{ QLocale() };
|
||||
|
||||
const bool showThousandsSeparator = false;
|
||||
const int numDecimalPlaces = 2;
|
||||
QString testString = "0" + QString(testLocale.decimalPoint()) + "12";
|
||||
EXPECT_EQ(testString, AzQtComponents::toString(0.1234, numDecimalPlaces, testLocale, showThousandsSeparator));
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_AllZerosButOneWithLocale)
|
||||
{
|
||||
QLocale testLocale{ QLocale() };
|
||||
|
||||
const bool showThousandsSeparator = false;
|
||||
const int numDecimalPlaces = 2;
|
||||
QString testString = "1" + QString(testLocale.decimalPoint()) + "0";
|
||||
EXPECT_EQ(testString, AzQtComponents::toString(1.0000, numDecimalPlaces, testLocale, showThousandsSeparator));
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_TruncateShowThousandsSeparatorTruncateNoRoundWithLocale)
|
||||
{
|
||||
QLocale testLocale{ QLocale() };
|
||||
|
||||
const bool showThousandsSeparator = true;
|
||||
const int numDecimalPlaces = 3;
|
||||
QString testString = "1" + QString(testLocale.groupSeparator()) + "000" + QString(testLocale.decimalPoint()) + "123";
|
||||
EXPECT_EQ(testString, AzQtComponents::toString(1000.1236, numDecimalPlaces, testLocale, showThousandsSeparator));
|
||||
}
|
||||
|
||||
TEST(AzQtComponents, FloatToString_TruncateShowThousandsSeparatorOnlyOneDecimalWithLocale)
|
||||
{
|
||||
QLocale testLocale{ QLocale() };
|
||||
|
||||
const bool showThousandsSeparator = true;
|
||||
int numDecimalPlaces = 2;
|
||||
QString testString = "1" + QString(testLocale.groupSeparator()) + "000" + QString(testLocale.decimalPoint()) + "0";
|
||||
EXPECT_EQ(testString, AzQtComponents::toString(1000.000, numDecimalPlaces, testLocale, showThousandsSeparator));
|
||||
}
|
||||
|
||||
@@ -245,12 +245,15 @@ namespace UnitTest
|
||||
{
|
||||
using testing::StrEq;
|
||||
|
||||
QLocale testLocale{ QLocale() };
|
||||
QString testString = "10" + QString(testLocale.decimalPoint()) + "0";
|
||||
|
||||
m_doubleSpinBox->setSuffix("m");
|
||||
m_doubleSpinBox->setValue(10.0);
|
||||
|
||||
// test internal logic (textFromValue() calls private StringValue())
|
||||
QString value = m_doubleSpinBox->textFromValue(10.0);
|
||||
EXPECT_THAT(value.toUtf8().constData(), StrEq("10.0"));
|
||||
EXPECT_THAT(value.toUtf8().constData(), testString);
|
||||
|
||||
m_doubleSpinBox->setFocus();
|
||||
EXPECT_THAT(m_doubleSpinBox->suffix().toUtf8().constData(), StrEq(""));
|
||||
@@ -293,31 +296,44 @@ namespace UnitTest
|
||||
|
||||
TEST_F(SpinBoxFixture, SpinBoxCheckHighValueTruncatesCorrectly)
|
||||
{
|
||||
QString value = setupTruncationTest("0.9999999");
|
||||
QLocale testLocale{ QLocale() };
|
||||
QString testString = "0" + QString(testLocale.decimalPoint()) + "9999999";
|
||||
QString value = setupTruncationTest(testString);
|
||||
|
||||
EXPECT_TRUE(value == "0.999");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "999";
|
||||
EXPECT_TRUE(value == testString);
|
||||
}
|
||||
|
||||
TEST_F(SpinBoxFixture, SpinBoxCheckLowValueTruncatesCorrectly)
|
||||
{
|
||||
QString value = setupTruncationTest("0.0000001");
|
||||
QLocale testLocale{ QLocale() };
|
||||
QString testString = "0" + QString(testLocale.decimalPoint()) + "0000001";
|
||||
QString value = setupTruncationTest(testString);
|
||||
|
||||
EXPECT_TRUE(value == "0.0");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "0";
|
||||
EXPECT_TRUE(value == testString);
|
||||
}
|
||||
|
||||
TEST_F(SpinBoxFixture, SpinBoxCheckBugValuesTruncatesCorrectly)
|
||||
{
|
||||
QString value = setupTruncationTest("0.12395");
|
||||
QLocale testLocale{ QLocale() };
|
||||
QString testString = "0" + QString(testLocale.decimalPoint()) + "12395";
|
||||
QString value = setupTruncationTest(testString);
|
||||
|
||||
EXPECT_TRUE(value == "0.123");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "123";
|
||||
EXPECT_TRUE(value == testString);
|
||||
|
||||
value = setupTruncationTest("0.94496");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "94496";
|
||||
value = setupTruncationTest(testString);
|
||||
|
||||
EXPECT_TRUE(value == "0.944");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "944";
|
||||
EXPECT_TRUE(value == testString);
|
||||
|
||||
value = setupTruncationTest("0.0009999");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "0009999";
|
||||
value = setupTruncationTest(testString);
|
||||
|
||||
EXPECT_TRUE(value == "0.0");
|
||||
testString = "0" + QString(testLocale.decimalPoint()) + "0";
|
||||
EXPECT_TRUE(value == testString);
|
||||
}
|
||||
|
||||
} // namespace UnitTest
|
||||
|
||||
@@ -56,8 +56,6 @@ namespace O3DE::ProjectManager
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||
|
||||
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
AzQtComponents::Utilities::HandleDpiAwareness(AzQtComponents::Utilities::SystemDpiAware);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user