File: signature_unittest.cc

package info (click to toggle)
chromium 141.0.7390.107-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,246,132 kB
  • sloc: cpp: 35,264,965; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,635; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,313; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (63 lines) | stat: -rw-r--r-- 2,307 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/dbus/utils/signature.h"

#include <map>
#include <string>
#include <tuple>
#include <vector>

#include "components/dbus/utils/variant.h"
#include "dbus/object_path.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace dbus_utils {
namespace {

// Helper to get a signature as a std::string.
template <typename T>
std::string GetSignature() {
  return internal::GetDBusTypeSignature<T>();
}

TEST(DBusSignatureTest, GetSignature) {
  using TestTuple = std::tuple<int32_t, std::string, std::vector<uint8_t>>;
  using TestTupleWithVector = std::tuple<std::string, std::vector<int32_t>>;
  using TestTupleWithMap = std::tuple<int32_t, std::map<std::string, bool>>;
  using TestMapWithTupleKey = std::map<std::tuple<int32_t, std::string>, bool>;

  EXPECT_EQ(GetSignature<bool>(), "b");
  EXPECT_EQ(GetSignature<int16_t>(), "n");
  EXPECT_EQ(GetSignature<uint16_t>(), "q");
  EXPECT_EQ(GetSignature<int32_t>(), "i");
  EXPECT_EQ(GetSignature<uint32_t>(), "u");
  EXPECT_EQ(GetSignature<int64_t>(), "x");
  EXPECT_EQ(GetSignature<uint64_t>(), "t");
  EXPECT_EQ(GetSignature<double>(), "d");
  EXPECT_EQ(GetSignature<uint8_t>(), "y");
  EXPECT_EQ(GetSignature<std::string>(), "s");
  EXPECT_EQ(GetSignature<dbus::ObjectPath>(), "o");
  EXPECT_EQ(GetSignature<Variant>(), "v");
  EXPECT_EQ(GetSignature<base::ScopedFD>(), "h");

  EXPECT_EQ(GetSignature<std::vector<int32_t>>(), "ai");
  EXPECT_EQ(GetSignature<std::vector<std::string>>(), "as");
  EXPECT_EQ(GetSignature<std::vector<bool>>(), "ab");
  EXPECT_EQ(GetSignature<std::vector<std::vector<int32_t>>>(), "aai");

  EXPECT_EQ((GetSignature<std::map<std::string, int32_t>>()), "a{si}");

  EXPECT_EQ(GetSignature<TestTuple>(), "(isay)");
  EXPECT_EQ(GetSignature<TestTupleWithVector>(), "(sai)");
  EXPECT_EQ(GetSignature<TestTupleWithMap>(), "(ia{sb})");
  EXPECT_EQ(GetSignature<TestMapWithTupleKey>(), "a{(is)b}");

  EXPECT_EQ((GetSignature<std::vector<TestTuple>>()), "a(isay)");
  EXPECT_EQ((GetSignature<std::map<std::string, TestTuple>>()), "a{s(isay)}");
  EXPECT_EQ((GetSignature<std::map<TestTuple, int32_t>>()), "a{(isay)i}");
}

}  // namespace
}  // namespace dbus_utils