~larryprice/libertine-scope/filter-state

« back to all changes in this revision

Viewing changes to tests/test_blacklist.cpp

  • Committer: Tarmac
  • Author(s): Larry Price
  • Date: 2016-06-14 14:07:43 UTC
  • mfrom: (45.2.9 minor-cmake-updates)
  • Revision ID: tarmac-20160614140743-z3gy1pl2mqk4k3p8
Refactor Query class for consistent style and extract some functionality to helper classes.

Approved by Christopher Townsend, Libertine CI Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it under
 
5
 * the terms of the GNU General Public License, version 3, as published by the
 
6
 * Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
#include "libertine-scope/blacklist.h"
 
17
#include <gtest/gtest.h>
 
18
#include <QDir>
 
19
#include <QTemporaryDir>
 
20
 
 
21
 
 
22
namespace
 
23
{
 
24
class TestBlacklistFixture : public ::testing::Test
 
25
{
 
26
public:
 
27
  TestBlacklistFixture()
 
28
    : blacklist(QString("%1/data").arg(QDir::currentPath()).toStdString())
 
29
  {
 
30
  }
 
31
 
 
32
protected:
 
33
  Blacklist blacklist;
 
34
};
 
35
 
 
36
TEST_F(TestBlacklistFixture, ReturnsFalseWhenFileDoesNotExist)
 
37
{
 
38
  EXPECT_FALSE(Blacklist(QTemporaryDir().path().toStdString()).app_is_blacklisted("app1", "container1"));
 
39
}
 
40
 
 
41
TEST_F(TestBlacklistFixture, ReturnsFalseWhenAppIsNotInTheList)
 
42
{
 
43
  EXPECT_FALSE(blacklist.app_is_blacklisted("app5", "container1"));
 
44
}
 
45
 
 
46
TEST_F(TestBlacklistFixture, ReturnsTrueWhenAppIsBlacklistedLocally)
 
47
{
 
48
  EXPECT_TRUE(blacklist.app_is_blacklisted("app1", "container1"));
 
49
}
 
50
 
 
51
TEST_F(TestBlacklistFixture, ReturnsTrueWhenAppIsBlacklistedGlobally)
 
52
{
 
53
  EXPECT_TRUE(blacklist.app_is_blacklisted("app2", "container2"));
 
54
}
 
55
 
 
56
TEST_F(TestBlacklistFixture, ReturnsFalseWhenAppIsWhitelistedLocally)
 
57
{
 
58
  EXPECT_FALSE(blacklist.app_is_blacklisted("app3", "container1"));
 
59
}
 
60
 
 
61
TEST_F(TestBlacklistFixture, ReturnsFalseWhenAppIsWhitelistedGlobally)
 
62
{
 
63
  EXPECT_FALSE(blacklist.app_is_blacklisted("app4", "container2"));
 
64
}
 
65
}