1/* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#include "testing/gtest/include/gtest/gtest.h" 12#include "webrtc/video_engine/test/auto_test/primitives/fake_stdin.h" 13#include "webrtc/video_engine/test/auto_test/primitives/input_helpers.h" 14 15namespace webrtc { 16 17class InputHelpersTest: public testing::Test { 18}; 19 20TEST_F(InputHelpersTest, AcceptsAnyInputExceptEmptyByDefault) { 21 FILE* fake_stdin = FakeStdin("\n\nWhatever\n"); 22 std::string result = TypedInput("Title") 23 .WithInputSource(fake_stdin).AskForInput(); 24 EXPECT_EQ("Whatever", result); 25 fclose(fake_stdin); 26} 27 28TEST_F(InputHelpersTest, ReturnsDefaultOnEmptyInputIfDefaultSet) { 29 FILE* fake_stdin = FakeStdin("\n\nWhatever\n"); 30 std::string result = TypedInput("Title") 31 .WithInputSource(fake_stdin) 32 .WithDefault("MyDefault") 33 .AskForInput(); 34 EXPECT_EQ("MyDefault", result); 35 fclose(fake_stdin); 36} 37 38TEST_F(InputHelpersTest, ObeysInputValidator) { 39 class ValidatorWhichOnlyAcceptsFooBar : public InputValidator { 40 public: 41 bool InputOk(const std::string& input) const { 42 return input == "FooBar"; 43 } 44 }; 45 FILE* fake_stdin = FakeStdin("\nFoo\nBar\nFoo Bar\nFooBar\n"); 46 std::string result = TypedInput("Title") 47 .WithInputSource(fake_stdin) 48 .WithInputValidator(new ValidatorWhichOnlyAcceptsFooBar()) 49 .AskForInput(); 50 EXPECT_EQ("FooBar", result); 51 fclose(fake_stdin); 52} 53 54TEST_F(InputHelpersTest, OverrideRegistryParsesOverridesCorrectly) { 55 // TODO(phoglund): Ignore spaces where appropriate 56 OverrideRegistry override_registry("My Title=Value,My Choice=1"); 57 EXPECT_TRUE(override_registry.HasOverrideFor("My Title")); 58 EXPECT_EQ("Value", override_registry.GetOverrideFor("My Title")); 59 EXPECT_TRUE(override_registry.HasOverrideFor("My Choice")); 60 EXPECT_EQ("1", override_registry.GetOverrideFor("My Choice")); 61 EXPECT_FALSE(override_registry.HasOverrideFor("Not Overridden")); 62} 63 64TEST_F(InputHelpersTest, ObeysOverridesBeforeAnythingElse) { 65 class CarelessValidator : public InputValidator { 66 public: 67 bool InputOk(const std::string& input) const { 68 return true; 69 } 70 }; 71 FILE* fake_stdin = FakeStdin("\nFoo\nBar\nFoo Bar\nFooBar\n"); 72 OverrideRegistry override_registry("My Title=Value,My Choice=1"); 73 EXPECT_EQ("Value", InputBuilder("My Title", 74 new CarelessValidator(), override_registry) 75 .WithDefault("Whatever") 76 .WithInputSource(fake_stdin).AskForInput()); 77 fclose(fake_stdin); 78} 79 80}; 81