~charlesk/indicator-datetime/lp-1001595

« back to all changes in this revision

Viewing changes to tests/test-indicator.cc

  • Committer: CI bot
  • Author(s): Charles Kerr
  • Date: 2014-01-31 11:46:08 UTC
  • mfrom: (290.2.86 cpp)
  • Revision ID: ps-jenkins@lists.canonical.com-20140131114608-8sfzhimcfdywmk46
Finally land this. Other, still open bugs will be fixed in subsequent commits. Fixes: 793450, 1271484, 1274046

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright 2012 Canonical Ltd.
3
 
 
4
 
Authors:
5
 
    Charles Kerr <charles.kerr@canonical.com>
6
 
 
7
 
This program is free software: you can redistribute it and/or modify it 
8
 
under the terms of the GNU General Public License version 3, as published 
9
 
by the Free Software Foundation.
10
 
 
11
 
This program is distributed in the hope that it will be useful, but 
12
 
WITHOUT ANY WARRANTY; without even the implied warranties of 
13
 
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
14
 
PURPOSE.  See the GNU General Public License for more details.
15
 
 
16
 
You should have received a copy of the GNU General Public License along 
17
 
with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
*/
19
 
 
20
 
#include <gtest/gtest.h>
21
 
 
22
 
#include <glib-object.h>
23
 
 
24
 
/***
25
 
****
26
 
***/
27
 
 
28
 
namespace
29
 
{
30
 
  void ensure_glib_initialized ()
31
 
  {
32
 
    static bool initialized = false;
33
 
 
34
 
    if (G_UNLIKELY(!initialized))
35
 
    {
36
 
      initialized = true;
37
 
      g_setenv ("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
38
 
    }
39
 
  }
40
 
}
41
 
 
42
 
/***
43
 
****
44
 
***/
45
 
 
46
 
class IndicatorTest : public ::testing::Test
47
 
{
48
 
  private:
49
 
 
50
 
    guint log_handler_id;
51
 
 
52
 
    int log_count_ipower_actual;
53
 
 
54
 
    static void log_count_func (const gchar *log_domain,
55
 
                                GLogLevelFlags log_level,
56
 
                                const gchar *message,
57
 
                                gpointer user_data)
58
 
    {
59
 
      reinterpret_cast<IndicatorTest*>(user_data)->log_count_ipower_actual++;
60
 
    }
61
 
 
62
 
  protected:
63
 
 
64
 
    int log_count_ipower_expected;
65
 
 
66
 
  protected:
67
 
 
68
 
    virtual void SetUp()
69
 
    {
70
 
      const GLogLevelFlags flags = GLogLevelFlags(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING);
71
 
      log_handler_id = g_log_set_handler ("Indicator-Power", flags, log_count_func, this);
72
 
      log_count_ipower_expected = 0;
73
 
      log_count_ipower_actual = 0;
74
 
 
75
 
      ensure_glib_initialized ();
76
 
    }
77
 
 
78
 
    virtual void TearDown()
79
 
    {
80
 
      ASSERT_EQ (log_count_ipower_expected, log_count_ipower_actual);
81
 
      g_log_remove_handler ("Indicator-Power", log_handler_id);
82
 
    }
83
 
};
84
 
 
85
 
/***
86
 
****
87
 
***/
88
 
 
89
 
TEST_F(IndicatorTest, HelloWorld)
90
 
{
91
 
  ASSERT_TRUE (TRUE);
92
 
}