This source file includes following definitions.
- SetUp
- TearDown
- DisplayAvailable
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chromeos/ime/xkeyboard.h"
#include <algorithm>
#include <set>
#include <string>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <X11/Xlib.h>
namespace chromeos {
namespace input_method {
namespace {
class XKeyboardTest : public testing::Test {
public:
XKeyboardTest() {
}
virtual void SetUp() {
xkey_.reset(XKeyboard::Create());
}
virtual void TearDown() {
xkey_.reset();
}
scoped_ptr<XKeyboard> xkey_;
base::MessageLoopForUI message_loop_;
};
bool DisplayAvailable() {
return (base::MessagePumpForUI::GetDefaultXDisplay() != NULL);
}
}
TEST_F(XKeyboardTest, TestCheckLayoutName) {
EXPECT_FALSE(XKeyboard::CheckLayoutNameForTesting("us!"));
EXPECT_FALSE(XKeyboard::CheckLayoutNameForTesting("us; /bin/sh"));
EXPECT_TRUE(XKeyboard::CheckLayoutNameForTesting("ab-c_12"));
EXPECT_FALSE(XKeyboard::CheckLayoutNameForTesting("US"));
for (int c = 'a'; c <= 'z'; ++c) {
EXPECT_TRUE(XKeyboard::CheckLayoutNameForTesting(std::string(3, c)));
}
for (int c = '0'; c <= '9'; ++c) {
EXPECT_TRUE(XKeyboard::CheckLayoutNameForTesting(std::string(3, c)));
}
EXPECT_TRUE(XKeyboard::CheckLayoutNameForTesting("us(dvorak)"));
EXPECT_TRUE(XKeyboard::CheckLayoutNameForTesting("jp"));
}
TEST_F(XKeyboardTest, TestSetCapsLockEnabled) {
if (!DisplayAvailable()) {
DVLOG(1) << "X server is not available. Skip the test.";
return;
}
const bool initial_lock_state = xkey_->CapsLockIsEnabled();
xkey_->SetCapsLockEnabled(true);
EXPECT_TRUE(xkey_->CapsLockIsEnabled());
xkey_->SetCapsLockEnabled(false);
EXPECT_FALSE(xkey_->CapsLockIsEnabled());
xkey_->SetCapsLockEnabled(true);
EXPECT_TRUE(xkey_->CapsLockIsEnabled());
xkey_->SetCapsLockEnabled(false);
EXPECT_FALSE(xkey_->CapsLockIsEnabled());
xkey_->SetCapsLockEnabled(initial_lock_state);
}
TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) {
if (!DisplayAvailable()) {
DVLOG(1) << "X server is not available. Skip the test.";
return;
}
const bool state = XKeyboard::GetAutoRepeatEnabledForTesting();
xkey_->SetAutoRepeatEnabled(!state);
EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting());
xkey_->SetAutoRepeatEnabled(state);
EXPECT_EQ(state, XKeyboard::GetAutoRepeatEnabledForTesting());
}
TEST_F(XKeyboardTest, TestSetAutoRepeatRate) {
if (!DisplayAvailable()) {
DVLOG(1) << "X server is not available. Skip the test.";
return;
}
AutoRepeatRate rate;
EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&rate));
AutoRepeatRate tmp(rate);
++tmp.initial_delay_in_ms;
++tmp.repeat_interval_in_ms;
EXPECT_TRUE(xkey_->SetAutoRepeatRate(tmp));
EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp));
EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms);
EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms);
EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate));
EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp));
EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms);
EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms);
}
}
}