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
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index ff4cb71..c12ae6b 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -871,3 +871,24 @@
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
+}