op.cpp 2.43 KB
Newer Older
1
//*****************************************************************************
2
// Copyright 2017-2019 Intel Corporation
3 4
//
// Licensed under the Apache License, Version 2.0 (the "License");
5 6 7
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
8
//     http://www.apache.org/licenses/LICENSE-2.0
9 10 11 12 13
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
14 15
// limitations under the License.
//*****************************************************************************
16 17 18 19 20 21

#include <memory>
#include <sstream>
#include <string>
#include <vector>

22
#include "gmock/gmock.h"
23 24
#include "gtest/gtest.h"

25
#include "ngraph/graph_util.hpp"
26
#include "ngraph/ngraph.hpp"
27 28 29 30 31 32

using namespace std;
using namespace ngraph;

TEST(op, is_op)
{
33
    auto arg0 = make_shared<op::Parameter>(element::f32, Shape{1});
34 35 36 37 38 39
    ASSERT_NE(nullptr, arg0);
    EXPECT_TRUE(arg0->is_parameter());
}

TEST(op, is_parameter)
{
40
    auto arg0 = make_shared<op::Parameter>(element::f32, Shape{1});
41
    ASSERT_NE(nullptr, arg0);
42
    auto t0 = make_shared<op::Add>(arg0, arg0);
43 44 45
    ASSERT_NE(nullptr, t0);
    EXPECT_FALSE(t0->is_parameter());
}
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

TEST(op, provenance_tag)
{
    auto node = make_shared<op::Parameter>(element::f32, Shape{1});
    auto tag1 = "parameter node";
    auto tag2 = "f32 node";
    node->add_provenance_tag(tag1);
    node->add_provenance_tag(tag2);

    node->remove_provenance_tag(tag1);

    auto tags = node->get_provenance_tags();
    ASSERT_TRUE(tags.find(tag1) == tags.end());
    ASSERT_TRUE(tags.find(tag2) != tags.end());
}

// TODO: Need to mock Node, Op etc to be able to unit test functions like replace_node().
// Mocking them directly isn't possible because google test requires methods to be
// non-virtual. For non-virtual methods we will need to templatize these classes and call using
// different template argument between testing and production.
/*
TEST(op, provenance_replace_node)
{
    class MockOp: public op::Op
    {
        MOCK_CONST_METHOD1(copy_with_new_args, std::shared_ptr<Node>(const NodeVector& new_args));
        MOCK_CONST_METHOD1(get_users, NodeVector (bool check_is_used)); // This can't be mocked as it's non-virtual
    };

    ::testing::NiceMock<MockOp> mock_op;
}
*/