File: TestMatchResult.cpp

package info (click to toggle)
gmenuharness 0.1.4-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 316 kB
  • sloc: cpp: 1,834; ansic: 14; makefile: 11
file content (98 lines) | stat: -rw-r--r-- 3,029 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (C) 2015 Canonical, Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Pete Woods <pete.woods@canonical.com>
 */

#include <lomiri/gmenuharness/MatchResult.h>

#include <gtest/gtest.h>

using namespace std;
namespace mh = lomiri::gmenuharness;

namespace
{

class TestMatchResult : public testing::Test
{
};

TEST_F(TestMatchResult, SuccessFailAndMessage)
{
    mh::MatchResult matchResult;
    EXPECT_TRUE(matchResult.success());

    matchResult.failure({1, 2, 3}, "the message");
    matchResult.failure({1, 3, 4}, "the other message");
    EXPECT_FALSE(matchResult.success());
    EXPECT_EQ("Failed expectations:\n 1 2 3 the message\n 1 3 4 the other message\n", matchResult.concat_failures());
}

TEST_F(TestMatchResult, MergeTwoFailed)
{
    mh::MatchResult matchResult;
    matchResult.failure({1, 2, 3}, "m1a");
    matchResult.failure({1, 3, 4}, "m1b");

    mh::MatchResult matchResult2;
    matchResult2.failure({2, 2, 3}, "m2a");
    matchResult2.failure({2, 3, 4}, "m2b");
    EXPECT_FALSE(matchResult2.success());

    matchResult.merge(matchResult2);
    EXPECT_FALSE(matchResult.success());
    EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n 2 2 3 m2a\n 2 3 4 m2b\n", matchResult.concat_failures());
}

TEST_F(TestMatchResult, MergeFailedIntoSuccess)
{
    mh::MatchResult matchResult;
    EXPECT_TRUE(matchResult.success());

    mh::MatchResult matchResult2;
    matchResult2.failure({2, 2, 3}, "m2a");
    matchResult2.failure({2, 3, 4}, "m2b");
    EXPECT_FALSE(matchResult2.success());

    matchResult.merge(matchResult2);
    EXPECT_FALSE(matchResult.success());
    EXPECT_EQ("Failed expectations:\n 2 2 3 m2a\n 2 3 4 m2b\n", matchResult.concat_failures());
}

TEST_F(TestMatchResult, CopyAssignment)
{
    mh::MatchResult matchResult;
    matchResult.failure({1, 2, 3}, "m1a");
    matchResult.failure({1, 3, 4}, "m1b");

    // Copy constructor
    {
        mh::MatchResult matchResult2(matchResult);
        EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures());
    }
    // Assignment operator
    {
        mh::MatchResult matchResult2 = matchResult;
        EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures());
    }
    // Move operator
    {
        mh::MatchResult matchResult2 = move(matchResult);
        EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures());
    }
}

}