diff options
Diffstat (limited to 'tests/unit_tests/notify.cpp')
-rw-r--r-- | tests/unit_tests/notify.cpp | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/tests/unit_tests/notify.cpp b/tests/unit_tests/notify.cpp index d6811c6bd..cd70b7739 100644 --- a/tests/unit_tests/notify.cpp +++ b/tests/unit_tests/notify.cpp @@ -26,6 +26,10 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#ifdef __GLIBC__ +#include <sys/stat.h> +#endif + #include "gtest/gtest.h" #include <boost/filesystem.hpp> @@ -37,21 +41,50 @@ TEST(notify, works) { - char name_template[] = "/tmp/monero-notify-unit-test-XXXXXX"; +#ifdef __GLIBC__ + mode_t prevmode = umask(077); +#endif + const char *tmp = getenv("TEMP"); + if (!tmp) + tmp = "/tmp"; + static const char *filename = "monero-notify-unit-test-XXXXXX"; + const size_t len = strlen(tmp) + 1 + strlen(filename); + std::unique_ptr<char[]> name_template_(new char[len + 1]); + char *name_template = name_template_.get(); + ASSERT_TRUE(name_template != NULL); + snprintf(name_template, len + 1, "%s/%s", tmp, filename); int fd = mkstemp(name_template); +#ifdef __GLIBC__ + umask(prevmode); +#endif ASSERT_TRUE(fd >= 0); close(fd); - const std::string spec = epee::string_tools::get_current_module_folder() + "/test_notifier " + name_template + " %s"; + const std::string spec = epee::string_tools::get_current_module_folder() + "/test_notifier" +#ifdef _WIN32 + + ".exe" +#endif + + " " + name_template + " %s"; tools::Notify notify(spec.c_str()); notify.notify("1111111111111111111111111111111111111111111111111111111111111111"); - epee::misc_utils::sleep_no_w(100); - - std::string s; - ASSERT_TRUE(epee::file_io_utils::load_file_to_string(name_template, s)); - ASSERT_TRUE(s == "1111111111111111111111111111111111111111111111111111111111111111"); + bool ok = false; + for (int i = 0; i < 10; ++i) + { + epee::misc_utils::sleep_no_w(100); + std::string s; + if (epee::file_io_utils::load_file_to_string(name_template, s)) + { + if (s == "1111111111111111111111111111111111111111111111111111111111111111") + { + ok = true; + break; + } + std::cout << "got: [" << s << "]" << std::endl; + } + } boost::filesystem::remove(name_template); + ASSERT_TRUE(ok); } |