File: test_leak_rfl_tup.cpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (67 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (2)
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
64
65
66
67
#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <source_location>
#include <string>
#include <vector>

#include "write_and_read.hpp"

namespace test_leak_rfl_tup {

class TestLeak {
 public:
  inline static int create_count = 0;
  inline static int delete_count = 0;

  using ReflectionType = std::string;

  TestLeak(const std::string& _str) : moved_(false), str_(_str) {
    ++create_count;
  }

  TestLeak(const TestLeak& _other) : moved_(false), str_(_other.str_) {
    ++create_count;
  }

  TestLeak(TestLeak&& _other) noexcept
      : moved_(false), str_(std::move(_other.str_)) {
    _other.moved_ = true;
    ++create_count;
    ++delete_count;
  }

  ~TestLeak() {
    if (!moved_) {
      ++delete_count;
    }
  }

  TestLeak& operator=(const TestLeak& _other) {
    str_ = _other.str_;
    return *this;
  }

  TestLeak& operator=(TestLeak&& _other) noexcept {
    str_ = std::move(_other.str_);
    _other.moved_ = true;
    ++delete_count;
    return *this;
  }

  const std::string& reflection() { return str_; }

 private:
  bool moved_;
  std::string str_;
};

TEST(json, test_leak_rfl_tup) {
  {
    const auto r =
        rfl::json::read<rfl::Tuple<std::string, std::string, const TestLeak>>(
            R"(["Homer","Simpson","test"])");
  }
  EXPECT_EQ(TestLeak::delete_count, TestLeak::create_count);
}
}  // namespace test_leak_rfl_tup