• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 43152560159

12 Nov 2026 04:05AM UTC coverage: 60.414% (+1.7%) from 58.699%
43152560159

push

github

jcelerier
Tests: the CLAP checker keeps a plug-in factory given for any id its own

A target that answers every factory id with its plug-in factory
(SpectMorph) had the checker hand the host the target's own, unwrapped,
for preset discovery: the host could not tell it from a discovery factory
as it can without the checker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufUMRpkKzaYvUs9iHW

229543 of 687702 branches covered (33.38%)

247114 of 409035 relevant lines covered (60.41%)

742286.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/clappuppet/clappuppet.cpp
1
#include <score/tools/PuppetClient.hpp>
2

3
#include <clap/all.h>
4

5
#include <filesystem>
6
#include <iostream>
7

8
#if defined(_MSC_VER)
9
#include <boost/asio/impl/src.hpp>
10
#endif
11

12
// https://svn.boost.org/trac10/ticket/3605
13
#if defined(_MSC_VER)
14
#include <boost/asio/detail/winsock_init.hpp>
15
#pragma warning(push)
16
#pragma warning(disable : 4073)
17
#pragma init_seg(lib)
18
boost::asio::detail::winsock_init<2, 2>::manual manual_winsock_init;
19
#pragma warning(pop)
20
#elif defined(_WIN32)
21
#include <boost/asio/detail/winsock_init.hpp>
22
#endif
23

24
#if !defined(__cpp_exceptions)
25
#include <boost/throw_exception.hpp>
26
namespace boost
27
{
28
void throw_exception(std::exception const& e)
29
{
30
  std::terminate();
31
}
32
void throw_exception(std::exception const& e, boost::source_location const& loc)
33
{
34
  std::terminate();
35
}
36
}
37
#endif
38

39
#if defined(_WIN32)
40
#include <windows.h>
41
#else
42
#include <dlfcn.h>
43
#endif
44

45
std::string load_clap(const std::string& path, int id, const std::string& token)
×
46
{
47
  using score::puppet::json_escape;
48
  auto error_json = [&](std::string err) {
×
49
    return fmt::format(
×
50
        R"_({{"Path":"{}","Request":{},"Token":"{}","Error":"{}"}})_",
×
51
        json_escape(path), id, json_escape(token), json_escape(err));
×
52
  };
×
53

54
  try
55
  {
56
    const bool isFile = std::filesystem::exists(path);
×
57
    if(!isFile)
×
58
    {
59
      std::cerr << "Invalid path: " << path << std::endl;
×
60
      return error_json("Invalid path");
×
61
    }
62

63
    // Load the plugin library
64
#if defined(_WIN32)
65
    HMODULE handle = LoadLibraryA(path.c_str());
66
    if(!handle)
67
    {
68
      std::cerr << "Failed to load library: " << path << std::endl;
69
      return error_json("Failed to load library");
70
    }
71

72
    auto entry_fn = (const clap_plugin_entry_t*)GetProcAddress(handle, "clap_entry");
73
#else
74
    void* handle = dlopen(path.c_str(), RTLD_LAZY);
×
75
    if(!handle)
×
76
    {
77
      const char* err = dlerror();
×
78
      std::cerr << "Failed to load library: " << path << " - " << (err ? err : "")
×
79
                << std::endl;
×
80
      return error_json(std::string{"Failed to load library: "} + (err ? err : ""));
×
81
    }
82
    
83
    auto entry_fn = (const clap_plugin_entry_t*)dlsym(handle, "clap_entry");
×
84
#endif
85

86
    if(!entry_fn)
×
87
    {
88
      std::cerr << "No clap_entry found in: " << path << std::endl;
×
89
#if defined(_WIN32)
90
      FreeLibrary(handle);
91
#else
92
      dlclose(handle);
×
93
#endif
94
      return error_json("No clap_entry found");
×
95
    }
96

97
    // clap/entry.h: on macOS init() takes the bundle, not the binary in it
98
    std::string init_path = path;
×
99
#if defined(__APPLE__)
100
    if(auto p = path.rfind(".clap/Contents/MacOS/"); p != std::string::npos)
101
      init_path = path.substr(0, p + 5);
102
#endif
103
    if(!entry_fn->init(init_path.c_str()))
×
104
    {
105
      std::cerr << "Failed to initialize CLAP plugin: " << path << std::endl;
×
106
#if defined(_WIN32)
107
      FreeLibrary(handle);
108
#else
109
      dlclose(handle);
×
110
#endif
111
      return error_json("Failed to initialize CLAP plugin");
×
112
    }
113

114
    auto factory = (const clap_plugin_factory_t*)entry_fn->get_factory(CLAP_PLUGIN_FACTORY_ID);
×
115
    if(!factory)
×
116
    {
117
      std::cerr << "No plugin factory found in: " << path << std::endl;
×
118
      entry_fn->deinit();
×
119
#if defined(_WIN32)
120
      FreeLibrary(handle);
121
#else
122
      dlclose(handle);
×
123
#endif
124
      return error_json("No plugin factory found");
×
125
    }
126

127
    std::string root = fmt::format(
×
128
        R"_({{
×
129
"Path":"{}",
130
"Request":{},
131
"Token":"{}",
132
"Plugins":[
133
)_",
134
        json_escape(path), id, json_escape(token));
×
135

136
    uint32_t plugin_count = factory->get_plugin_count(factory);
×
137
    bool first_plugin = true;
×
138
    for(uint32_t i = 0; i < plugin_count; ++i)
×
139
    {
140
      const clap_plugin_descriptor_t* desc = factory->get_plugin_descriptor(factory, i);
×
141
      if(!desc)
×
142
        continue;
×
143

144
      std::string features_str = "[";
×
145
      if(desc->features)
×
146
      {
147
        bool first = true;
×
148
        for(const char* const* feature = desc->features; *feature; ++feature)
×
149
        {
150
          if(!first) features_str += ",";
×
151
          features_str += fmt::format("\"{}\"", json_escape(*feature));
×
152
          first = false;
×
153
        }
×
154
      }
×
155
      features_str += "]";
×
156

157
      auto plugin_json = fmt::format(
×
158
          R"_({{
×
159
"ID":"{}",
160
"Name":"{}",
161
"Vendor":"{}",
162
"Version":"{}",
163
"URL":"{}",
164
"ManualURL":"{}",
165
"SupportURL":"{}",
166
"Description":"{}",
167
"Features":{}
168
}})_",
169
          json_escape(desc->id ? desc->id : ""),
×
170
          json_escape(desc->name ? desc->name : ""),
×
171
          json_escape(desc->vendor ? desc->vendor : ""),
×
172
          json_escape(desc->version ? desc->version : ""),
×
173
          json_escape(desc->url ? desc->url : ""),
×
174
          json_escape(desc->manual_url ? desc->manual_url : ""),
×
175
          json_escape(desc->support_url ? desc->support_url : ""),
×
176
          json_escape(desc->description ? desc->description : ""),
×
177
          features_str);
178

179
      if(!first_plugin)
×
180
        root += ",\n";
×
181
      root += plugin_json;
×
182
      first_plugin = false;
×
183
    }
×
184

185
    root += "]\n}";
×
186

187
    entry_fn->deinit();
×
188
#if defined(_WIN32)
189
    FreeLibrary(handle);
190
#else
191
    dlclose(handle);
×
192
#endif
193

194
    return root;
×
195
  }
×
196
  catch(const std::exception& e)
197
  {
198
    std::cerr << "Exception: " << e.what() << std::endl;
×
199
    return error_json(std::string{"Exception: "} + e.what());
×
200
  }
×
201
  catch(...)
202
  {
203
    return error_json("Unknown exception");
×
204
  }
×
205
}
×
206

207
void init_invisible_window();
208
int main(int argc, char** argv)
×
209
{
210
  init_invisible_window();
×
211

212
  return score::puppet::puppet_main(
×
213
      argc, argv, 37589, "clappuppet", true, 30,
×
214
      [](const std::string& path, int id, const std::string& token) {
×
215
    return load_clap(path, id, token);
×
216
      });
217
}
218

219
#include <score/tools/WinMainToMain.hpp>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc