Electroneum
notify.cpp File Reference
#include "gtest/gtest.h"
#include <boost/filesystem.hpp>
#include "misc_language.h"
#include "string_tools.h"
#include "file_io_utils.h"
#include "common/notify.h"
Include dependency graph for notify.cpp:

Go to the source code of this file.

Functions

 TEST (notify, works)
 

Function Documentation

◆ TEST()

TEST ( notify  ,
works   
)

Definition at line 42 of file notify.cpp.

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  {
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 }
::std::string string
Definition: gtest-port.h:1097
bool load_file_to_string(const std::string &path_to_file, std::string &target_str, size_t max_size=1000000000)
bool sleep_no_w(long ms)
std::string & get_current_module_folder()
Definition: string_tools.h:233
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
int notify(const char *tag, const char *s,...)
Definition: notify.cpp:65