1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // These tests have been added to specifically tests issues arising from (A)LPC
14 #include "sandbox/win/src/sandbox.h"
15 #include "sandbox/win/src/sandbox_factory.h"
16 #include "sandbox/win/src/sandbox_policy.h"
17 #include "sandbox/win/tests/common/controller.h"
18 #include "sandbox/win/tests/common/test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h"
23 // Converts LCID to std::wstring for passing to sbox tests.
24 std::wstring
LcidToWString(LCID lcid
) {
25 wchar_t buff
[10] = {0};
26 int res
= swprintf_s(buff
, sizeof(buff
)/sizeof(buff
[0]), L
"%08x", lcid
);
28 return std::wstring(buff
);
30 return std::wstring();
33 // Converts LANGID to std::wstring for passing to sbox tests.
34 std::wstring
LangidToWString(LANGID langid
) {
35 wchar_t buff
[10] = {0};
36 int res
= swprintf_s(buff
, sizeof(buff
)/sizeof(buff
[0]), L
"%04x", langid
);
38 return std::wstring(buff
);
40 return std::wstring();
43 SBOX_TESTS_COMMAND
int Lpc_GetUserDefaultLangID(int argc
, wchar_t **argv
) {
45 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND
;
46 std::wstring
expected_langid_string(argv
[0]);
48 // This will cause an exception if not warmed up suitably.
49 LANGID langid
= ::GetUserDefaultLangID();
51 std::wstring langid_string
= LangidToWString(langid
);
52 if (0 == wcsncmp(langid_string
.c_str(), expected_langid_string
.c_str(), 4)) {
53 return SBOX_TEST_SUCCEEDED
;
55 return SBOX_TEST_FAILED
;
58 TEST(LpcPolicyTest
, GetUserDefaultLangID
) {
59 LANGID langid
= ::GetUserDefaultLangID();
60 std::wstring cmd
= L
"Lpc_GetUserDefaultLangID " + LangidToWString(langid
);
62 EXPECT_EQ(SBOX_TEST_SUCCEEDED
, runner
.RunTest(cmd
.c_str()));
65 SBOX_TESTS_COMMAND
int Lpc_GetUserDefaultLCID(int argc
, wchar_t **argv
) {
67 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND
;
68 std::wstring
expected_lcid_string(argv
[0]);
70 // This will cause an exception if not warmed up suitably.
71 LCID lcid
= ::GetUserDefaultLCID();
73 std::wstring lcid_string
= LcidToWString(lcid
);
74 if (0 == wcsncmp(lcid_string
.c_str(), expected_lcid_string
.c_str(), 8)) {
75 return SBOX_TEST_SUCCEEDED
;
77 return SBOX_TEST_FAILED
;
80 TEST(LpcPolicyTest
, GetUserDefaultLCID
) {
81 LCID lcid
= ::GetUserDefaultLCID();
82 std::wstring cmd
= L
"Lpc_GetUserDefaultLCID " + LcidToWString(lcid
);
84 EXPECT_EQ(SBOX_TEST_SUCCEEDED
, runner
.RunTest(cmd
.c_str()));
87 SBOX_TESTS_COMMAND
int Lpc_GetUserDefaultLocaleName(int argc
, wchar_t **argv
) {
89 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND
;
90 std::wstring
expected_locale_name(argv
[0]);
92 wchar_t locale_name
[LOCALE_NAME_MAX_LENGTH
] = { 0 };
93 // This will cause an exception if not warmed up suitably.
94 int ret
= ::GetUserDefaultLocaleName(locale_name
, LOCALE_NAME_MAX_LENGTH
);
96 return SBOX_TEST_FAILED
;
98 if (!wcsnlen(locale_name
, LOCALE_NAME_MAX_LENGTH
)) {
99 return SBOX_TEST_FAILED
;
101 if (0 == wcsncmp(locale_name
,
102 expected_locale_name
.c_str(),
103 LOCALE_NAME_MAX_LENGTH
)) {
104 return SBOX_TEST_SUCCEEDED
;
106 return SBOX_TEST_FAILED
;
109 TEST(LpcPolicyTest
, GetUserDefaultLocaleName
) {
110 wchar_t locale_name
[LOCALE_NAME_MAX_LENGTH
] = { 0 };
111 int ret
= ::GetUserDefaultLocaleName(locale_name
, LOCALE_NAME_MAX_LENGTH
);
113 std::wstring cmd
= L
"Lpc_GetUserDefaultLocaleName " + \
114 std::wstring(locale_name
);
116 EXPECT_EQ(SBOX_TEST_SUCCEEDED
, runner
.RunTest(cmd
.c_str()));
119 } // namespace sandbox