Skip to content

Commit 16a345e

Browse files
authored
Add test to ensure the locale does not change (#155)
1 parent 6b5d207 commit 16a345e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ set(SourceFiles
8282
Source/MainComponent.cpp
8383
Source/PluginTests.cpp
8484
Source/tests/BasicTests.cpp
85+
Source/tests/LocaleTest.cpp
8586
Source/tests/BusTests.cpp
8687
Source/tests/ParameterFuzzTests.cpp
8788
Source/TestUtilities.cpp

Source/tests/LocaleTest.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*==============================================================================
2+
3+
Copyright 2018 by Tracktion Corporation.
4+
For more information visit www.tracktion.com
5+
6+
You may also use this code under the terms of the GPL v3 (see
7+
www.gnu.org/licenses).
8+
9+
pluginval IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
10+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
11+
DISCLAIMED.
12+
13+
==============================================================================*/
14+
15+
#include "../PluginTests.h"
16+
#include "../TestUtilities.h"
17+
18+
//==============================================================================
19+
struct LocaleTest : public PluginTest
20+
{
21+
LocaleTest()
22+
: PluginTest ("Ensuring that the locale does not change during execution", 1)
23+
{
24+
startupLocale = std::setlocale(LC_ALL, nullptr);
25+
}
26+
27+
void runTest (PluginTests& ut, juce::AudioPluginInstance& instance) override
28+
{
29+
ut.logMessage (juce::String ("INFO: Startup Locale: [LOC]")
30+
.replace ("LOC",juce::String (startupLocale), false));
31+
32+
if (instance.hasEditor())
33+
{
34+
ScopedPluginDeinitialiser scopedPluginDeinitialiser (instance);
35+
36+
{
37+
ut.logMessage ("Opening editor...");
38+
ScopedEditorShower editor (instance);
39+
}
40+
}
41+
42+
std::string newLocale = std::setlocale(LC_ALL, nullptr);
43+
ut.expectEquals (startupLocale, newLocale, "Plugin changed locale. This can cause unexpected behavior.");
44+
ut.logMessage (juce::String ("INFO: Shutdown Locale: [LOC]")
45+
.replace ("LOC",juce::String (newLocale), false));
46+
47+
}
48+
49+
private:
50+
std::string startupLocale;
51+
};
52+
53+
static LocaleTest localeTest;
54+

0 commit comments

Comments
 (0)