Skip to content

Commit

Permalink
Tests: add a test for Threads::InitializationCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
tamiko committed Oct 24, 2023
1 parent 3c4f1cd commit db782cf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/base/initialization_check_01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2005 - 2021 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------


// check numbers::is_finite

#include <deal.II/base/initialization_check.h>

#include <iostream>

#include "../tests.h"

using namespace dealii;

class Consumer
{
public:
void
do_something()
{
deallog << "called do_something" << std::endl;
initialization_check.check_and_initialize(
[&]() { deallog << "called initializer" << std::endl; });
}

private:
Threads::InitializationCheck initialization_check;
};

int
main()
{
initlog();

deallog << "consumer_1:" << std::endl;
Consumer consumer_1;
consumer_1.do_something();
consumer_1.do_something();

deallog << "consumer_2 (copy constructed, already initialized):" << std::endl;
auto consumer_2 = consumer_1;
consumer_2.do_something();

deallog << "consumer_3:" << std::endl;
Consumer consumer_3;
consumer_3.do_something();
deallog << "consumer_3 (copy assignment, already initialized):" << std::endl;
consumer_3 = consumer_1;
consumer_3.do_something();
deallog << "consumer_3 (move assignment, uninitialized):" << std::endl;
consumer_3 = Consumer();
consumer_3.do_something();

deallog << "OK!" << std::endl;
return 0;
}
16 changes: 16 additions & 0 deletions tests/base/initialization_check_01.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

DEAL::consumer_1:
DEAL::called do_something
DEAL::called initializer
DEAL::called do_something
DEAL::consumer_2 (copy constructed, already initialized):
DEAL::called do_something
DEAL::consumer_3:
DEAL::called do_something
DEAL::called initializer
DEAL::consumer_3 (copy assignment, already initialized):
DEAL::called do_something
DEAL::consumer_3 (move assignment, uninitialized):
DEAL::called do_something
DEAL::called initializer
DEAL::OK!

0 comments on commit db782cf

Please sign in to comment.