aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/time/tzdb/1.cc
blob: 796f3a8b4256883943de8c47638a4c46beddec8f (plain)
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
// { dg-do run { target c++20 } }
// { dg-require-effective-target cxx11_abi }

#include <chrono>
#include <testsuite_hooks.h>

using namespace std::chrono;

void
test_version()
{
  const tzdb& db = get_tzdb();
  VERIFY( &db == &get_tzdb_list().front() );

  const char* func;
  try {
    func = "remote_version";
    VERIFY( db.version == remote_version() );
    func = "reload_tzdb";
    const tzdb& reloaded = reload_tzdb();
    if (reloaded.version == db.version)
      VERIFY( &reloaded == &db );
  } catch (const std::exception&) {
    std::printf("std::chrono::%s() failed\n", func);
  }
}

void
test_current()
{
  const tzdb& db = get_tzdb();
  const time_zone* tz = db.current_zone();
  VERIFY( tz == std::chrono::current_zone() );
}

void
test_locate()
{
  const tzdb& db = get_tzdb();
  const time_zone* tz = db.locate_zone("GMT");
  VERIFY( tz != nullptr );
  VERIFY( tz->name() == "Etc/GMT" );
  VERIFY( tz == std::chrono::locate_zone("GMT") );
  VERIFY( tz == db.locate_zone("Etc/GMT") );
  VERIFY( tz == db.locate_zone("Etc/GMT+0") );

  VERIFY( db.locate_zone(db.current_zone()->name()) == db.current_zone() );
}

void
test_all_zones()
{
  const tzdb& db = get_tzdb();

  for (const auto& zone : db.zones)
    VERIFY( locate_zone(zone.name())->name() == zone.name() );

  for (const auto& link : db.links)
    VERIFY( locate_zone(link.name()) == locate_zone(link.target()) );
}

int main()
{
  test_version();
  test_current();
  test_locate();
}