1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "gtest/gtest.h"
16 #include "common/hostname.h"
17 #include "common/SubProcess.h"
19 #include <sys/types.h>
32 std::string exec(const char* cmd) {
33 std::array<char, 128> buffer;
35 std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
36 if (!pipe) throw std::runtime_error("popen() failed!");
37 while (!feof(pipe.get())) {
38 if (fgets(buffer.data(), 128, pipe.get()) != NULL)
39 result += buffer.data();
42 return result.substr(0, result.size()-1);;
45 TEST(Hostname, full) {
46 std::string hn = ceph_get_hostname();
47 ASSERT_EQ(hn, exec("hostname")) ;
52 TEST(Hostname, short) {
53 std::string shn = ceph_get_short_hostname();
54 ASSERT_EQ(shn, exec("hostname -s")) ;