ValidationUtilTest.cpp 2.4 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>

#include "utils/ValidationUtil.h"
#include "utils/Error.h"
10
#include "db/ExecutionEngine.h"
J
jinhai 已提交
11 12 13

#include <string>

14
using namespace zilliz::milvus;
J
jinhai 已提交
15 16 17 18
using namespace zilliz::milvus::server;

TEST(ValidationUtilTest, TableNameTest) {
    std::string table_name = "Normal123_";
G
groot 已提交
19
    ServerError res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
20 21 22
    ASSERT_EQ(res, SERVER_SUCCESS);

    table_name = "12sds";
G
groot 已提交
23
    res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
24 25 26
    ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);

    table_name = "";
G
groot 已提交
27
    res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
28 29 30
    ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);

    table_name = "_asdasd";
G
groot 已提交
31
    res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
32 33 34
    ASSERT_EQ(res, SERVER_SUCCESS);

    table_name = "!@#!@";
G
groot 已提交
35
    res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
36 37 38
    ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);

    table_name = "中文";
G
groot 已提交
39
    res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
40 41 42 43
    ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);


    table_name = std::string('a', 32768);
G
groot 已提交
44
    res = ValidationUtil::ValidateTableName(table_name);
J
jinhai 已提交
45 46 47 48 49
    ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
}


TEST(ValidationUtilTest, TableDimensionTest) {
G
groot 已提交
50 51 52 53 54
    ASSERT_EQ(ValidationUtil::ValidateTableDimension(-1), SERVER_INVALID_VECTOR_DIMENSION);
    ASSERT_EQ(ValidationUtil::ValidateTableDimension(0), SERVER_INVALID_VECTOR_DIMENSION);
    ASSERT_EQ(ValidationUtil::ValidateTableDimension(16385), SERVER_INVALID_VECTOR_DIMENSION);
    ASSERT_EQ(ValidationUtil::ValidateTableDimension(16384), SERVER_SUCCESS);
    ASSERT_EQ(ValidationUtil::ValidateTableDimension(1), SERVER_SUCCESS);
J
jinhai 已提交
55 56 57
}

TEST(ValidationUtilTest, TableIndexTypeTest) {
G
groot 已提交
58
    ASSERT_EQ(ValidationUtil::ValidateTableIndexType((int)engine::EngineType::INVALID), SERVER_INVALID_INDEX_TYPE);
59
    for(int i = 1; i <= (int)engine::EngineType::MAX_VALUE; i++) {
G
groot 已提交
60
        ASSERT_EQ(ValidationUtil::ValidateTableIndexType(i), SERVER_SUCCESS);
61
    }
G
groot 已提交
62
    ASSERT_EQ(ValidationUtil::ValidateTableIndexType((int)engine::EngineType::MAX_VALUE + 1), SERVER_INVALID_INDEX_TYPE);
J
jinhai 已提交
63
}