xref: /aosp_15_r20/external/protobuf/vendor_suffix_test.cpp (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1 #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 
TEST(vendor_suffix,suffix)12 TEST(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",
27        GOOGLE_PROTOBUF_VERSION / 1000 % 1000,
28        GOOGLE_PROTOBUF_VERSION % 1000);
29 
30     std::string suffix = GOOGLE_PROTOBUF_VERSION_SUFFIX;
31     if (suffix != "") {
32         version += "-" + suffix;
33     }
34 
35     std::vector<std::string> expect = {
36         "libprotobuf-cpp-full" + version + ".so",
37         "libprotobuf-cpp-lite" + version + ".so",
38     };
39 
40     ASSERT_EQ(expect, libs);
41 }
42