Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
notify.cpp
Go to the documentation of this file.
1
// Copyright (c) 2018, The Monero Project
2
//
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without modification, are
6
// permitted provided that the following conditions are met:
7
//
8
// 1. Redistributions of source code must retain the above copyright notice, this list of
9
// conditions and the following disclaimer.
10
//
11
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12
// of conditions and the following disclaimer in the documentation and/or other
13
// materials provided with the distribution.
14
//
15
// 3. Neither the name of the copyright holder nor the names of its contributors may be
16
// used to endorse or promote products derived from this software without specific
17
// prior written permission.
18
//
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
#ifdef __GLIBC__
30
#include <sys/stat.h>
31
#endif
32
33
#include "gtest/gtest.h"
34
35
#include <boost/filesystem.hpp>
36
37
#include "
misc_language.h
"
38
#include "
string_tools.h
"
39
#include "
file_io_utils.h
"
40
#include "
common/notify.h
"
41
42
TEST
(notify, works)
43
{
44
#ifdef __GLIBC__
45
mode_t prevmode = umask(077);
46
#endif
47
const
char
*tmp = getenv(
"TEMP"
);
48
if
(!tmp)
49
tmp =
"/tmp"
;
50
static
const
char
*filename =
"electroneum-notify-unit-test-XXXXXX"
;
51
const
size_t
len = strlen(tmp) + 1 + strlen(filename);
52
std::unique_ptr<char[]> name_template_(
new
char
[len + 1]);
53
char
*name_template = name_template_.get();
54
ASSERT_TRUE
(name_template != NULL);
55
snprintf(name_template, len + 1,
"%s/%s"
, tmp, filename);
56
int
fd = mkstemp(name_template);
57
#ifdef __GLIBC__
58
umask(prevmode);
59
#endif
60
ASSERT_TRUE
(fd >= 0);
61
close(fd);
62
63
const
std::string spec =
epee::string_tools::get_current_module_folder
() +
"/test_notifier"
64
#ifdef _WIN32
65
+
".exe"
66
#endif
67
+
" "
+ name_template +
" %s"
;
68
69
tools::Notify
notify(spec.c_str());
70
notify.
notify
(
"%s"
,
"1111111111111111111111111111111111111111111111111111111111111111"
, NULL);
71
72
bool
ok =
false
;
73
for
(
int
i = 0; i < 10; ++i)
74
{
75
epee::misc_utils::sleep_no_w
(100);
76
77
std::string s;
78
if
(
epee::file_io_utils::load_file_to_string
(name_template, s))
79
{
80
if
(s ==
"1111111111111111111111111111111111111111111111111111111111111111"
)
81
{
82
ok =
true
;
83
break
;
84
}
85
}
86
}
87
boost::filesystem::remove(name_template);
88
ASSERT_TRUE
(ok);
89
}
tools::Notify
Definition
notify.h:38
tools::Notify::notify
int notify(const char *tag, const char *s,...)
Definition
notify.cpp:65
TEST
#define TEST(test_case_name, test_name)
Definition
gtest.h:2187
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition
gtest.h:1865
file_io_utils.h
misc_language.h
epee::file_io_utils::load_file_to_string
bool load_file_to_string(const std::string &path_to_file, std::string &target_str, size_t max_size=1000000000)
Definition
file_io_utils.h:130
epee::misc_utils::sleep_no_w
bool sleep_no_w(long ms)
Definition
misc_language.h:100
epee::string_tools::get_current_module_folder
std::string & get_current_module_folder()
Definition
string_tools.h:233
notify.h
string_tools.h
tests
unit_tests
notify.cpp
Generated on
for Electroneum by
1.17.0