1/*******************************************************************************
2* Copyright 2017-2022 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#include "dnnl_test_common.hpp"
18#include "gtest/gtest.h"
19
20#include "oneapi/dnnl/dnnl.hpp"
21
22namespace dnnl {
23
24class handle_test_t : public ::testing::Test {
25public:
26 engine e;
27
28protected:
29 void SetUp() override { e = get_test_engine(); }
30};
31
32TEST_F(handle_test_t, TestHandleConstructorsAndOperators) {
33 // The initial state is 0
34 convolution_forward::primitive_desc pd;
35 ASSERT_TRUE((bool)pd == false);
36 ASSERT_TRUE((dnnl_primitive_desc_t)pd == nullptr);
37
38 // Dummy descriptor just to be able to create a pd
39 pd = convolution_forward::primitive_desc(e, prop_kind::forward_inference,
40 algorithm::convolution_direct,
41 {{1, 16, 7, 7}, memory::data_type::f32, memory::format_tag::any},
42 {{16, 16, 1, 1}, memory::data_type::f32, memory::format_tag::any},
43 {{1, 16, 7, 7}, memory::data_type::f32, memory::format_tag::any},
44 {1, 1}, {0, 0}, {0, 0});
45
46 // Copy from pd to pd1
47 auto pd1 = pd;
48 ASSERT_TRUE(pd1 == pd);
49
50 // This should set pd's handle to 0
51 pd1 = std::move(pd);
52 ASSERT_TRUE(pd1 != pd);
53 ASSERT_TRUE((dnnl_primitive_desc_t)pd == nullptr);
54}
55
56} // namespace dnnl
57