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

OpenLightingProject / ola / 21336882381

25 Jan 2026 05:47PM UTC coverage: 45.06% (-0.7%) from 45.72%
21336882381

Pull #1984

github

web-flow
Merge b8c8613eb into 704337b09
Pull Request #1984: Add conditionals for Protobuf 22+ API changes

8556 of 19814 branches covered (43.18%)

5 of 6 new or added lines in 3 files covered. (83.33%)

324 existing lines in 56 files now uncovered.

22100 of 49046 relevant lines covered (45.06%)

48.42 hits per line

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

79.31
/protoc/GeneratorHelpers.cpp
1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc.  All rights reserved.
3
// http://code.google.com/p/protobuf/
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
//     * Redistributions of source code must retain the above copyright
10
// notice, this list of conditions and the following disclaimer.
11
//     * Redistributions in binary form must reproduce the above
12
// copyright notice, this list of conditions and the following disclaimer
13
// in the documentation and/or other materials provided with the
14
// distribution.
15
//     * Neither the name of Google Inc. nor the names of its
16
// contributors may be used to endorse or promote products derived from
17
// this software without specific prior written permission.
18
//
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30

31
// Author: kenton@google.com (Kenton Varda)
32
//  Based on original Protocol Buffers design by
33
//  Sanjay Ghemawat, Jeff Dean, and others.
34
//
35
// Edited by Simon Newton for OLA
36

37
#include <google/protobuf/stubs/common.h>
38

39
#include <string>
40

41
#include "protoc/GeneratorHelpers.h"
42
#include "protoc/StrUtil.h"
43

44
using std::string;
45
using google::protobuf::Descriptor;
46

47
namespace ola {
48

49
namespace {
50

51
string DotsToUnderscores(const string& name) {
324✔
52
  return StringReplace(name, ".", "_", true);
648✔
53
}
54

55
string DotsToColons(const string& name) {
324✔
56
  return StringReplace(name, ".", "::", true);
648✔
57
}
58

59
}  // namespace
60

61
const char kThickSeparator[] =
62
  "// ===================================================================\n";
63
const char kThinSeparator[] =
64
  "// -------------------------------------------------------------------\n";
65

66
string ClassName(const Descriptor* descriptor, bool qualified) {
324✔
67
  // Find "outer", the descriptor of the top-level message in which
68
  // "descriptor" is embedded.
69
  const Descriptor* outer = descriptor;
324✔
70
  while (outer->containing_type() != NULL) outer = outer->containing_type();
324✔
71

72
  const string& outer_name = string(outer->full_name());
324✔
73
  string inner_name = string(descriptor->full_name()).substr(outer_name.size());
324✔
74

75
  if (qualified) {
324✔
76
    return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);
648✔
77
  } else {
NEW
78
    return string(outer->name()) + DotsToUnderscores(inner_name);
×
79
  }
80
}
324✔
81

82
string StripProto(const string& filename) {
4✔
83
  if (HasSuffixString(filename, ".protodevel")) {
4✔
84
    return StripSuffixString(filename, ".protodevel");
×
85
  } else {
86
    return StripSuffixString(filename, ".proto");
8✔
87
  }
88
}
89

90
// Convert a file name into a valid identifier.
91
string FilenameIdentifier(const string& filename) {
6✔
92
  string result;
6✔
93
  for (unsigned int i = 0; i < filename.size(); i++) {
90✔
94
    if (ascii_isalnum(filename[i])) {
84✔
95
      result.push_back(filename[i]);
84✔
96
    } else {
97
      // Not alphanumeric.  To avoid any possibility of name conflicts we
98
      // use the hex code for the character.
99
      result.push_back('_');
×
100
      char buffer[kFastToBufferSize];
×
101
      result.append(FastHexToBuffer(static_cast<uint8_t>(filename[i]), buffer));
×
102
    }
103
  }
104
  return result;
6✔
105
}
×
106

107
// No longer needed since protobuf 3.2
108
#if GOOGLE_PROTOBUF_VERSION < 3002000
109
// Return the name of the AddDescriptors() function for a given file.
110
string GlobalAddDescriptorsName(const string& filename) {
111
  return "protobuf_AddDesc_" + FilenameIdentifier(filename);
112
}
113
#endif
114

115
// Return the name of the AssignDescriptors() function for a given file.
116
string GlobalAssignDescriptorsName(const string& filename) {
4✔
117
  return "protobuf_AssignDesc_" + FilenameIdentifier(filename);
8✔
118
}
119
}  // namespace ola
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc