File: test-cxx-compat.cc

package info (click to toggle)
libabigail 2.2-2
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 881,820 kB
  • sloc: xml: 572,528; cpp: 98,056; sh: 11,779; makefile: 2,951; ansic: 2,913; python: 1,345
file content (66 lines) | stat: -rw-r--r-- 1,411 bytes parent folder | download
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
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- Mode: C++ -*-
//
// Copyright (C) 2020-2022 Google, Inc.
//
// Author: Matthias Maennich

/// @file
///
/// This program tests libabigail's CXX compatibility layer.

#include "lib/catch.hpp"

#include "abg-cxx-compat.h"

using abg_compat::optional;

TEST_CASE("OptionalConstruction", "[abg_compat::optional]")
{
  optional<bool> opt1;
  REQUIRE_FALSE(opt1.has_value());

  optional<bool> opt2(true);
  REQUIRE(opt2.has_value());
  CHECK(opt2.value() == true);

  optional<bool> opt3(false);
  REQUIRE(opt3.has_value());
  CHECK(opt3.value() == false);
}

TEST_CASE("OptionalValue", "[abg_compat::optional]")
{
  optional<bool> opt;
  REQUIRE_FALSE(opt.has_value());
  REQUIRE_THROWS(opt.value());

  opt = true;
  REQUIRE_NOTHROW(opt.value());
  CHECK(opt.value() == true);
}

TEST_CASE("OptionalValueOr", "[abg_compat::optional]")
{
  optional<std::string> opt;
  REQUIRE_FALSE(opt.has_value());

  const std::string& mine = "mine";
  // Ensure we get a copy of our own value.
  CHECK(opt.value_or(mine) == mine);

  // Now set the value
  const std::string& other = "other";
  opt = other;
  CHECK(opt.value_or(mine) != mine);
  CHECK(opt.value_or(mine) == other);
}

TEST_CASE("OptionalDeref", "[abg_compat::optional]")
{
  optional<std::string> opt("asdf");
  REQUIRE(opt.has_value());

  CHECK(*opt == "asdf");
  CHECK(opt->size() == 4);
}