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 <stdio.h> 12 13#include "testing/gtest/include/gtest/gtest.h" 14#include "webrtc/video_engine/test/auto_test/primitives/choice_helpers.h" 15#include "webrtc/video_engine/test/auto_test/primitives/fake_stdin.h" 16 17namespace webrtc { 18 19class ChoiceHelpersTest : public testing::Test { 20}; 21 22TEST_F(ChoiceHelpersTest, SplitReturnsEmptyChoicesForEmptyInput) { 23 EXPECT_TRUE(SplitChoices("").empty()); 24} 25 26TEST_F(ChoiceHelpersTest, SplitHandlesSingleChoice) { 27 Choices choices = SplitChoices("Single Choice"); 28 EXPECT_EQ(1u, choices.size()); 29 EXPECT_EQ("Single Choice", choices[0]); 30} 31 32TEST_F(ChoiceHelpersTest, SplitHandlesSingleChoiceWithEndingNewline) { 33 Choices choices = SplitChoices("Single Choice\n"); 34 EXPECT_EQ(1u, choices.size()); 35 EXPECT_EQ("Single Choice", choices[0]); 36} 37 38TEST_F(ChoiceHelpersTest, SplitHandlesMultipleChoices) { 39 Choices choices = SplitChoices( 40 "Choice 1\n" 41 "Choice 2\n" 42 "Choice 3"); 43 EXPECT_EQ(3u, choices.size()); 44 EXPECT_EQ("Choice 1", choices[0]); 45 EXPECT_EQ("Choice 2", choices[1]); 46 EXPECT_EQ("Choice 3", choices[2]); 47} 48 49TEST_F(ChoiceHelpersTest, SplitHandlesMultipleChoicesWithEndingNewline) { 50 Choices choices = SplitChoices( 51 "Choice 1\n" 52 "Choice 2\n" 53 "Choice 3\n"); 54 EXPECT_EQ(3u, choices.size()); 55 EXPECT_EQ("Choice 1", choices[0]); 56 EXPECT_EQ("Choice 2", choices[1]); 57 EXPECT_EQ("Choice 3", choices[2]); 58} 59 60TEST_F(ChoiceHelpersTest, CanSelectUsingChoiceBuilder) { 61 FILE* fake_stdin = FakeStdin("1\n2\n"); 62 EXPECT_EQ(1, FromChoices("Title", 63 "Choice 1\n" 64 "Choice 2").WithInputSource(fake_stdin).Choose()); 65 EXPECT_EQ(2, FromChoices("","Choice 1\n" 66 "Choice 2").WithInputSource(fake_stdin).Choose()); 67 fclose(fake_stdin); 68} 69 70TEST_F(ChoiceHelpersTest, RetriesIfGivenInvalidChoice) { 71 FILE* fake_stdin = FakeStdin("3\n0\n99\n23409234809\na\nwhatever\n1\n"); 72 EXPECT_EQ(1, FromChoices("Title", 73 "Choice 1\n" 74 "Choice 2").WithInputSource(fake_stdin).Choose()); 75 fclose(fake_stdin); 76} 77 78TEST_F(ChoiceHelpersTest, RetriesOnEnterIfNoDefaultSet) { 79 FILE* fake_stdin = FakeStdin("\n2\n"); 80 EXPECT_EQ(2, FromChoices("Title", 81 "Choice 1\n" 82 "Choice 2").WithInputSource(fake_stdin).Choose()); 83 fclose(fake_stdin); 84} 85 86TEST_F(ChoiceHelpersTest, PicksDefaultOnEnterIfDefaultSet) { 87 FILE* fake_stdin = FakeStdin("\n"); 88 EXPECT_EQ(2, FromChoices("Title", 89 "Choice 1\n" 90 "Choice 2").WithInputSource(fake_stdin) 91 .WithDefault("Choice 2").Choose()); 92 fclose(fake_stdin); 93} 94 95} // namespace webrtc 96