1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-23 00:49:38 +08:00
Files
opencv_contrib/modules/gapi/test/util/any_tests.cpp
Alexander Smorkalov 2d69dd1215 Merge pull request #3827 from asmorkalov:as/gapi_migration
Migrate G-API module from main repo to opencv_contrib #3827

Related to https://github.com/opencv/opencv/pull/26469
Required https://github.com/opencv/opencv/pull/26527
CI: https://github.com/opencv/ci-gha-workflow/pull/201

TODO:
- [x]  Python types generator fix
- [x] CI update

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2024-11-27 16:02:16 +03:00

143 lines
2.5 KiB
C++

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#include "../test_precomp.hpp"
#include <opencv2/gapi/util/any.hpp>
namespace opencv_test
{
TEST(Any, basic)
{
using namespace util;
any a(8);
auto casted_pointer = any_cast<int>(&a);
ASSERT_NE(nullptr, casted_pointer);
ASSERT_EQ(8, *casted_pointer);
*casted_pointer = 7;
ASSERT_EQ(7, any_cast<int>(a));
}
TEST(Any, any_cast_ref_throws_on_empty)
{
using namespace util;
any a;
ASSERT_THROW(util::any_cast<int>(a), bad_any_cast);
}
TEST(Any, copy)
{
using namespace util;
any a(8);
ASSERT_EQ(8, any_cast<int>(a));
any b (a);
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(a));
}
TEST(Any, copy_empty)
{
using namespace util;
any a;
ASSERT_EQ(nullptr, any_cast<int>(&a));
any b (a);
ASSERT_EQ(nullptr, any_cast<int>(&a));
ASSERT_EQ(nullptr, any_cast<int>(&b));
}
TEST(Any, move)
{
using namespace util;
any a(8);
ASSERT_EQ(8, any_cast<int>(a));
any b (std::move(a));
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(nullptr, any_cast<int>(&a));
}
TEST(Any, swap)
{
using namespace util;
any a(8);
any b(7);
ASSERT_EQ(7, any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(a));
swap(a,b);
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(7, any_cast<int>(a));
}
TEST(Any, move_assign)
{
using namespace util;
any a(8);
any b;
ASSERT_EQ(8, any_cast<int>(a));
b = (std::move(a));
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(nullptr, any_cast<int>(&a));
}
TEST(Any, copy_assign)
{
using namespace util;
any a(8);
any b;
ASSERT_EQ(8, any_cast<int>(a));
ASSERT_EQ(nullptr, any_cast<int>(&b));
b = a;
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(a));
}
TEST(Any, get_ref_to_val_from_any)
{
using namespace util;
int x = 8;
any a(x);
int& casted_ref = any_cast<int>(a);
ASSERT_EQ(8, casted_ref);
}
TEST(Any, update_val_via_ref)
{
using namespace util;
int x = 8;
any a(x);
int& casted_ref = any_cast<int>(a);
ASSERT_EQ(8, casted_ref);
casted_ref = 7;
ASSERT_EQ(7, any_cast<int>(a));
}
} // namespace opencv_test