summaryrefslogtreecommitdiff
path: root/tests/stdlib_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-01-22 20:46:12 -0800
committerElliott Hughes <enh@google.com>2020-01-23 08:28:48 -0800
commit75064c177fc11b032b4d68b60e6265f2c6c52d9b (patch)
tree7606da424e6caeae2ab13eecf3097a385324711b /tests/stdlib_test.cpp
parent73e9f242ed07631798433df4e35f5f73443cb9f9 (diff)
Initialize __progname correctly.
setprogname() does a basename, but we were initializing __progname directly. Stop doing that, and add some tests. Test: treehugger Change-Id: I06f306ade4161b2f0c7e314a3b1b30c9420117b7
Diffstat (limited to 'tests/stdlib_test.cpp')
-rw-r--r--tests/stdlib_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index ff4cb71ee..c12ae6b7e 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -871,3 +871,24 @@ TEST(stdlib, getloadavg) {
ASSERT_TRUE(fabs(expected[1] - load[1]) < 0.5) << expected[1] << ' ' << load[1];
ASSERT_TRUE(fabs(expected[2] - load[2]) < 0.5) << expected[2] << ' ' << load[2];
}
+
+TEST(stdlib, getprogname) {
+#if defined(__GLIBC__)
+ GTEST_SKIP() << "glibc doesn't have getprogname()";
+#else
+ // You should always have a name.
+ ASSERT_TRUE(getprogname() != nullptr);
+ // The name should never have a slash in it.
+ ASSERT_TRUE(strchr(getprogname(), '/') == nullptr);
+#endif
+}
+
+TEST(stdlib, setprogname) {
+#if defined(__GLIBC__)
+ GTEST_SKIP() << "glibc doesn't have setprogname()";
+#else
+ // setprogname() only takes the basename of what you give it.
+ setprogname("/usr/bin/muppet");
+ ASSERT_STREQ("muppet", getprogname());
+#endif
+}