blob: bd0642234570e9214041620b4efe2a723a49f9d7 [file] [log] [blame]
Colin Cross5bb33a52019-08-16 14:22:26 -07001#include <link.h>
2
3#include <string>
4#include <vector>
5
6#include <android-base/stringprintf.h>
7
8#include <gtest/gtest.h>
9
10#include <google/protobuf/message_lite.h>
11
12TEST(vendor_suffix, suffix) {
13 std::vector<std::string> libs;
14 dl_iterate_phdr([](dl_phdr_info* info, size_t, void* data) -> int {
15 auto local_libs = static_cast<decltype(&libs)>(data);
16 std::string name = info->dlpi_name;
17 size_t libprotobuf = name.find("libprotobuf-cpp");
18 if (libprotobuf != name.npos) {
19 local_libs->push_back(name.substr(libprotobuf, name.size()));
20 }
21 return 0;
22 }, &libs);
23
24 std::sort(libs.begin(), libs.end());
25
26 std::string version = android::base::StringPrintf("-%d.%d.%d",
27 GOOGLE_PROTOBUF_VERSION / 1000000,
28 GOOGLE_PROTOBUF_VERSION / 1000 % 1000,
29 GOOGLE_PROTOBUF_VERSION % 1000);
30
31 std::string suffix = GOOGLE_PROTOBUF_VERSION_SUFFIX;
32 if (suffix != "") {
33 version += "-" + suffix;
34 }
35
36 std::vector<std::string> expect = {
37 "libprotobuf-cpp-full" + version + ".so",
38 "libprotobuf-cpp-lite" + version + ".so",
39 };
40
41 ASSERT_EQ(expect, libs);
42}