<commit_before>/* 
 * Copyright 2015 Intel(r) Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http ://www.apache.org/licenses/LICENSE-2.0
 *
 * 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
 * limitations under the License.
 *
 */
#include "test_precomp.hpp"

#if TARGET_OS_IPHONE
extern std::string tempPath;
#define INTEGRATION_TEST_FILE (tempPath + "integration_test_file.avi")
#else
#define INTEGRATION_TEST_FILE "integration_test_file.avi"
#endif /* TARGET_OS_IPHONE */

TEST(Integration, InitializeAndTerminate)
{
    ASSERT_NO_THROW(vmf::initialize());
    ASSERT_NO_THROW(vmf::terminate());
}

TEST(Integration, fullFunctionality_1)
{
    copyFile(VIDEO_FILE, INTEGRATION_TEST_FILE);
    vmf::initialize();
    const vmf::vmf_string atom(TEST_SCHEMA_NAME_0);
    const vmf::vmf_string atom(TEST_SCHEMA_NAME_1);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_0);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_1);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_2);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_3);
    const vmf::vmf_string atom(TEST_FIELD_NAME_0);
    const vmf::vmf_string atom(TEST_FIELD_NAME_1);
    const vmf::vmf_string atom(TEST_FIELD_NAME_2);
    
    {
        std::shared_ptr<vmf::MetadataSchema> schema[2];
        schema[0] = std::shared_ptr<vmf::MetadataSchema>(new vmf::MetadataSchema(TEST_SCHEMA_NAME_0));
        schema[1] = std::shared_ptr<vmf::MetadataSchema>(new vmf::MetadataSchema(TEST_SCHEMA_NAME_1));
        std::shared_ptr<vmf::MetadataDesc> desc[4];
        desc[0] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_0, vmf::Variant::type_integer));
        desc[2] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_2, vmf::Variant::type_integer));
        std::vector<vmf::FieldDesc> fields[2];
        fields[0].push_back(vmf::FieldDesc(TEST_FIELD_NAME_0, vmf::Variant::type_string));
        fields[1].push_back(vmf::FieldDesc(TEST_FIELD_NAME_1, vmf::Variant::type_integer));
        fields[1].push_back(vmf::FieldDesc(TEST_FIELD_NAME_2, vmf::Variant::type_string));
        desc[1] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_1, fields[0]));
        desc[3] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_3, fields[1]));
        ASSERT_NO_THROW(schema[0]->add(desc[0]));
        ASSERT_NO_THROW(schema[0]->add(desc[1]));
        ASSERT_NO_THROW(schema[1]->add(desc[2]));
        ASSERT_NO_THROW(schema[1]->add(desc[3]));
        vmf::MetadataStream s;
        ASSERT_TRUE(s.open(INTEGRATION_TEST_FILE, vmf::MetadataStream::Update));
        ASSERT_NO_THROW(s.addSchema(schema[0]));
        ASSERT_NO_THROW(s.addSchema(schema[1]));
        s.save();
        ASSERT_NO_THROW(s.close());
    }

    const vmf::vmf_integer TEST_INT32_VALUE_1 = 1;
    const vmf::vmf_integer TEST_INT32_VALUE_2 = 2;
    const vmf::vmf_integer TEST_INT32_VALUE_3 = 3;
    const vmf::vmf_integer TEST_INT32_VALUE_4 = 4;
    const vmf::vmf_integer TEST_INT32_VALUE_5 = 5;
    const vmf::vmf_string atom(TEST_STRING_VALUE_1);
    const vmf::vmf_string atom(TEST_STRING_VALUE_2);
    const vmf::vmf_string atom(TEST_STRING_VALUE_3);
    const vmf::vmf_string atom(TEST_STRING_VALUE_4);

    {
        vmf::MetadataStream s;
        ASSERT_TRUE(s.open(INTEGRATION_TEST_FILE, vmf::MetadataStream::Update));
        std::shared_ptr<vmf::MetadataSchema> schema[2];
        schema[0] = s.getSchema(TEST_SCHEMA_NAME_0);
        ASSERT_TRUE(schema[0] != NULL);
        schema[1] = s.getSchema(TEST_SCHEMA_NAME_1);
        ASSERT_TRUE(schema[1] != NULL);
        std::shared_ptr<vmf::MetadataDesc> desc[4];
        ASSERT_NO_THROW(desc[0] = schema[0]->findMetadataDesc(TEST_PROPERTY_NAME_0));
        ASSERT_NO_THROW(desc[1] = schema[0]->findMetadataDesc(TEST_PROPERTY_NAME_1));
        ASSERT_NO_THROW(desc[2] = schema[1]->findMetadataDesc(TEST_PROPERTY_NAME_2));
        ASSERT_NO_THROW(desc[3] = schema[1]->findMetadataDesc(TEST_PROPERTY_NAME_3));
        std::shared_ptr<vmf::Metadata> metadata[4];
        metadata[0] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[0]));
        metadata[1] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[1]));
        metadata[2] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[2]));
        metadata[3] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[3]));
        metadata[0]->addValue(vmf::Variant(TEST_INT32_VALUE_1));
        metadata[2]->addValue(vmf::Variant(TEST_INT32_VALUE_3));
        metadata[1]->setFieldValue(TEST_FIELD_NAME_0, TEST_STRING_VALUE_1);
        metadata[3]->setFieldValue(TEST_FIELD_NAME_1, TEST_INT32_VALUE_5);
        metadata[3]->setFieldValue(TEST_FIELD_NAME_2, TEST_STRING_VALUE_3);
        for(int i = 0; i < 4; ++i) s.add(metadata[i]);
        s.save();
        s.close();
    }

    {
        vmf::MetadataStream s;
        ASSERT_TRUE(s.open(INTEGRATION_TEST_FILE, vmf::MetadataStream::Update));
        vmf::MetadataSet schema[2];
        s.load(TEST_SCHEMA_NAME_0);
        s.load(TEST_SCHEMA_NAME_1);
        schema[0] = s.queryBySchema(TEST_SCHEMA_NAME_0);
        schema[1] = s.queryBySchema(TEST_SCHEMA_NAME_1);
        vmf::MetadataSet prop[4];
        prop[0] = schema[0].queryByName(TEST_PROPERTY_NAME_0);
        prop[1] = schema[0].queryByName(TEST_PROPERTY_NAME_1);
        prop[2] = schema[1].queryByName(TEST_PROPERTY_NAME_2);
        prop[3] = schema[1].queryByName(TEST_PROPERTY_NAME_3);
        std::shared_ptr<vmf::Metadata> metadata[4];
        for(int i = 0; i < 4; ++i)
        {
            ASSERT_NO_THROW(metadata[i] = prop[i].at(0));
        }
        ASSERT_EQ(TEST_INT32_VALUE_1, (vmf::vmf_integer) metadata[0]->at(0));
        ASSERT_EQ(TEST_INT32_VALUE_3, (vmf::vmf_integer) metadata[2]->at(0));
        metadata[0]->addValue(vmf::Variant(TEST_INT32_VALUE_2));
        ASSERT_EQ(TEST_STRING_VALUE_1, (vmf::vmf_string) metadata[1]->getFieldValue(TEST_FIELD_NAME_0));
        ASSERT_EQ(TEST_INT32_VALUE_5, (vmf::vmf_integer) metadata[3]->getFieldValue(TEST_FIELD_NAME_1));
        ASSERT_EQ(TEST_STRING_VALUE_3, (vmf::vmf_string) metadata[3]->getFieldValue(TEST_FIELD_NAME_2));<commit_msg>more asserts added<commit_after>/* 
 * Copyright 2015 Intel(r) Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http ://www.apache.org/licenses/LICENSE-2.0
 *
 * 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
 * limitations under the License.
 *
 */
#include "test_precomp.hpp"

#if TARGET_OS_IPHONE
extern std::string tempPath;
#define INTEGRATION_TEST_FILE (tempPath + "integration_test_file.avi")
#else
#define INTEGRATION_TEST_FILE "integration_test_file.avi"
#endif /* TARGET_OS_IPHONE */

TEST(Integration, InitializeAndTerminate)
{
    ASSERT_NO_THROW(vmf::initialize());
    ASSERT_NO_THROW(vmf::terminate());
}

TEST(Integration, fullFunctionality_1)
{
    copyFile(VIDEO_FILE, INTEGRATION_TEST_FILE);
    vmf::initialize();
    const vmf::vmf_string atom(TEST_SCHEMA_NAME_0);
    const vmf::vmf_string atom(TEST_SCHEMA_NAME_1);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_0);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_1);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_2);
    const vmf::vmf_string atom(TEST_PROPERTY_NAME_3);
    const vmf::vmf_string atom(TEST_FIELD_NAME_0);
    const vmf::vmf_string atom(TEST_FIELD_NAME_1);
    const vmf::vmf_string atom(TEST_FIELD_NAME_2);
    
    {
        std::shared_ptr<vmf::MetadataSchema> schema[2];
        schema[0] = std::shared_ptr<vmf::MetadataSchema>(new vmf::MetadataSchema(TEST_SCHEMA_NAME_0));
        schema[1] = std::shared_ptr<vmf::MetadataSchema>(new vmf::MetadataSchema(TEST_SCHEMA_NAME_1));
        std::shared_ptr<vmf::MetadataDesc> desc[4];
        desc[0] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_0, vmf::Variant::type_integer));
        desc[2] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_2, vmf::Variant::type_integer));
        std::vector<vmf::FieldDesc> fields[2];
        fields[0].push_back(vmf::FieldDesc(TEST_FIELD_NAME_0, vmf::Variant::type_string));
        fields[1].push_back(vmf::FieldDesc(TEST_FIELD_NAME_1, vmf::Variant::type_integer));
        fields[1].push_back(vmf::FieldDesc(TEST_FIELD_NAME_2, vmf::Variant::type_string));
        desc[1] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_1, fields[0]));
        desc[3] = std::shared_ptr<vmf::MetadataDesc>(new vmf::MetadataDesc(TEST_PROPERTY_NAME_3, fields[1]));
        ASSERT_NO_THROW(schema[0]->add(desc[0]));
        ASSERT_NO_THROW(schema[0]->add(desc[1]));
        ASSERT_NO_THROW(schema[1]->add(desc[2]));
        ASSERT_NO_THROW(schema[1]->add(desc[3]));
        vmf::MetadataStream s;
        ASSERT_TRUE(s.open(INTEGRATION_TEST_FILE, vmf::MetadataStream::Update));
        ASSERT_NO_THROW(s.addSchema(schema[0]));
        ASSERT_NO_THROW(s.addSchema(schema[1]));
        ASSERT_TRUE(s.save());
        ASSERT_NO_THROW(s.close());
    }

    const vmf::vmf_integer TEST_INT32_VALUE_1 = 1;
    const vmf::vmf_integer TEST_INT32_VALUE_2 = 2;
    const vmf::vmf_integer TEST_INT32_VALUE_3 = 3;
    const vmf::vmf_integer TEST_INT32_VALUE_4 = 4;
    const vmf::vmf_integer TEST_INT32_VALUE_5 = 5;
    const vmf::vmf_string atom(TEST_STRING_VALUE_1);
    const vmf::vmf_string atom(TEST_STRING_VALUE_2);
    const vmf::vmf_string atom(TEST_STRING_VALUE_3);
    const vmf::vmf_string atom(TEST_STRING_VALUE_4);

    {
        vmf::MetadataStream s;
        ASSERT_TRUE(s.open(INTEGRATION_TEST_FILE, vmf::MetadataStream::Update));
        std::shared_ptr<vmf::MetadataSchema> schema[2];
        schema[0] = s.getSchema(TEST_SCHEMA_NAME_0);
        ASSERT_TRUE(schema[0] != NULL);
        schema[1] = s.getSchema(TEST_SCHEMA_NAME_1);
        ASSERT_TRUE(schema[1] != NULL);
        std::shared_ptr<vmf::MetadataDesc> desc[4];
        ASSERT_NO_THROW(desc[0] = schema[0]->findMetadataDesc(TEST_PROPERTY_NAME_0));
        ASSERT_NO_THROW(desc[1] = schema[0]->findMetadataDesc(TEST_PROPERTY_NAME_1));
        ASSERT_NO_THROW(desc[2] = schema[1]->findMetadataDesc(TEST_PROPERTY_NAME_2));
        ASSERT_NO_THROW(desc[3] = schema[1]->findMetadataDesc(TEST_PROPERTY_NAME_3));
        std::shared_ptr<vmf::Metadata> metadata[4];
        metadata[0] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[0]));
        metadata[1] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[1]));
        metadata[2] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[2]));
        metadata[3] = std::shared_ptr<vmf::Metadata>(new vmf::Metadata(desc[3]));
        metadata[0]->addValue(vmf::Variant(TEST_INT32_VALUE_1));
        metadata[2]->addValue(vmf::Variant(TEST_INT32_VALUE_3));
        metadata[1]->setFieldValue(TEST_FIELD_NAME_0, TEST_STRING_VALUE_1);
        metadata[3]->setFieldValue(TEST_FIELD_NAME_1, TEST_INT32_VALUE_5);
        metadata[3]->setFieldValue(TEST_FIELD_NAME_2, TEST_STRING_VALUE_3);
        for(int i = 0; i < 4; ++i) s.add(metadata[i]);
        ASSERT_TRUE(s.save());
        s.close();
    }

    {
        vmf::MetadataStream s;
        ASSERT_TRUE(s.open(INTEGRATION_TEST_FILE, vmf::MetadataStream::Update));
        vmf::MetadataSet schema[2];
        s.load(TEST_SCHEMA_NAME_0);
        s.load(TEST_SCHEMA_NAME_1);
        schema[0] = s.queryBySchema(TEST_SCHEMA_NAME_0);
        schema[1] = s.queryBySchema(TEST_SCHEMA_NAME_1);
        vmf::MetadataSet prop[4];
        prop[0] = schema[0].queryByName(TEST_PROPERTY_NAME_0);
        prop[1] = schema[0].queryByName(TEST_PROPERTY_NAME_1);
        prop[2] = schema[1].queryByName(TEST_PROPERTY_NAME_2);
        prop[3] = schema[1].queryByName(TEST_PROPERTY_NAME_3);
        std::shared_ptr<vmf::Metadata> metadata[4];
        for(int i = 0; i < 4; ++i)
        {
            ASSERT_NO_THROW(metadata[i] = prop[i].at(0));
        }
        ASSERT_EQ(TEST_INT32_VALUE_1, (vmf::vmf_integer) metadata[0]->at(0));
        ASSERT_EQ(TEST_INT32_VALUE_3, (vmf::vmf_integer) metadata[2]->at(0));
        metadata[0]->addValue(vmf::Variant(TEST_INT32_VALUE_2));
        ASSERT_EQ(TEST_STRING_VALUE_1, (vmf::vmf_string) metadata[1]->getFieldValue(TEST_FIELD_NAME_0));
        ASSERT_EQ(TEST_INT32_VALUE_5, (vmf::vmf_integer) metadata[3]->getFieldValue(TEST_FIELD_NAME_1));
        ASSERT_EQ(TEST_STRING_VALUE_3, (vmf::vmf_string) metadata[3]->getFieldValue(TEST_FIELD_NAME_2));
{'fraction_non_alphanumeric': 0.13887411684266504, 'fraction_numerical': 0.026437742156043456, 'mean_word_length': 4.766097240473062, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '969744', 'n_tokens_mistral': 4690, 'n_tokens_neox': 4670, 'n_words': 637}