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 25, 2023
1 parent 89942c1 commit e821b27
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/base/lazy_01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ---------------------------------------------------------------------
//
// 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.
//
// ---------------------------------------------------------------------


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

#include <iostream>

#include "../tests.h"

using namespace dealii;

int
main()
{
initlog();

{
Lazy<int> lazy_integer;

deallog << "lazy_integer.has_value() = " << lazy_integer.has_value()
<< std::endl;

lazy_integer.initialize([&]() {
deallog << "[initializing object]" << std::endl;
return 42;
});
deallog << "lazy_integer.has_value() = " << lazy_integer.has_value() << "\n"
<< "lazy_integer.value() = " << lazy_integer.value() << std::endl;

lazy_integer.initialize([&]() {
deallog << "[initializing object] again... not good." << std::endl;
return -1;
});

deallog << "lazy_integer.has_value() = " << lazy_integer.has_value() << "\n"
<< "lazy_integer.value() = " << lazy_integer.value() << std::endl;
}

{
Lazy<int> lazy_integer;

deallog << "lazy_integer.value() = "
<< lazy_integer.value_or_initialize([&]() {
deallog << "... [initializing object] ... ";
return 42;
})
<< std::endl;
}


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

DEAL::lazy_integer.has_value() = 0
DEAL::[initializing object]
DEAL::lazy_integer.has_value() = 1
lazy_integer.value() = 42
DEAL::lazy_integer.has_value() = 1
lazy_integer.value() = 42
DEAL::lazy_integer.value() = ... [initializing object] ... 42
DEAL::OK!

0 comments on commit e821b27

Please sign in to comment.