X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain_test.cpp;h=dd4ffa2254835978c77b7243a563867fd07a9411;hp=50d004db1c52c1192946b87add1b785149f585fc;hb=d88ed3150376693000665b9016c0350d5d90e9e1;hpb=5ee3e6bb0bf100d57a06911b89c3a0a0dc49e2be diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 50d004d..dd4ffa2 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -2,6 +2,10 @@ // // Note that this also contains the tests for some of the simpler effects. +#include +#include +#include + #include #include @@ -1041,4 +1045,45 @@ TEST(EffectChainTest, IdentityWithOwnPool) { movit_debug_level = MOVIT_DEBUG_OFF; } +// A dummy effect whose only purpose is to test sprintf decimal behavior. +class PrintfingBlueEffect : public Effect { +public: + PrintfingBlueEffect() {} + virtual string effect_type_id() const { return "PrintfingBlueEffect"; } + string output_fragment_shader() { + stringstream ss; + ss.imbue(locale("C")); + ss.precision(8); + ss << "vec4 FUNCNAME(vec2 tc) { return vec4(" + << 0.0f << ", " << 0.0f << ", " + << 0.5f << ", " << 1.0f << "); }\n"; + return ss.str(); + } +}; + +TEST(EffectChainTest, StringStreamLocalesWork) { + // An example of a locale with comma instead of period as decimal separator. + // Obviously, if you run on a machine without this locale available, + // the test will always succeed. Note that the OpenGL driver might call + // setlocale() behind-the-scenes, and that might corrupt the returned + // pointer, so we need to take our own copy of it here. + char *saved_locale = strdup(setlocale(LC_ALL, "nb_NO.UTF_8")); + float data[] = { + 0.0f, 0.0f, 0.0f, 0.0f, + }; + float expected_data[] = { + 0.0f, 0.0f, 0.5f, 1.0f, + }; + float out_data[4]; + EffectChainTester tester(data, 1, 1, FORMAT_RGBA_PREMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR); + tester.get_chain()->add_effect(new PrintfingBlueEffect()); + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR); + + expect_equal(expected_data, out_data, 4, 1); + + setlocale(LC_ALL, saved_locale); + free(saved_locale); +} + + } // namespace movit