File size: 2,608 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: LGPL-2.1-or-later

#include <gtest/gtest.h>
#include "src/App/InitApplication.h"

#include <memory>

#include <Mod/Spreadsheet/App/Sheet.h>
#include <Mod/Spreadsheet/App/PropertySheet.h>

class PropertySheetTest: public ::testing::Test
{
protected:
    static void SetUpTestSuite()
    {
        tests::initApplication();
    }
    void SetUp() override
    {
        _sheet = std::make_unique<Spreadsheet::Sheet>();
        _propertySheet = std::make_unique<Spreadsheet::PropertySheet>(_sheet.get());
    }
    void TearDown() override
    {
        _sheet.reset();
        _propertySheet.reset();
    }

    /// Get a non-owning pointer to the internal PropertySheet for this test
    Spreadsheet::PropertySheet* propertySheet()
    {
        return _propertySheet.get();
    }

private:
    std::unique_ptr<Spreadsheet::Sheet> _sheet;
    std::unique_ptr<Spreadsheet::PropertySheet> _propertySheet;
};

TEST_F(PropertySheetTest, isValidCellAddressNameValidNames)  // NOLINT
{
    std::vector<std::string> validAddressNames {"A1", "Z1024", "AA42", "ZZ4096"};
    for (const auto& name : validAddressNames) {
        EXPECT_TRUE(propertySheet()->isValidCellAddressName(name))
            << "\"" << name << "\" was not accepted as a cell name, and should be";
    }
}

TEST_F(PropertySheetTest, isValidCellAddressNameInvalidNames)  // NOLINT
{
    std::vector<std::string> invalidAddressNames {
        "Bork",
        "Bork_de_bork",
        "A",
        "42",
        "AAA1",     // Too many characters to start, AAA is not a valid column
        "ZZ123456"  // Too large a number to end, 123456 is not a valid row
    };
    for (const auto& name : invalidAddressNames) {
        EXPECT_FALSE(propertySheet()->isValidCellAddressName(name))
            << "\"" << name << "\" was accepted as a cell name, and should not be";
    }
}

TEST_F(PropertySheetTest, validAliases)  // NOLINT
{
    std::vector<std::string> validAliases {
        "Bork",
        "Bork_de_bork"
        "A",
        "AA123456"
    };
    for (const auto& name : validAliases) {
        EXPECT_TRUE(propertySheet()->isValidAlias(name))
            << "\"" << name << "\" was not accepted as an alias name, and should be";
    }
}

TEST_F(PropertySheetTest, invalidAliases)  // NOLINT
{
    std::vector<std::string>
        invalidAliases {"A1", "ZZ1234", "mm", "no spaces allowed", "\'NoLeadingQuotes"};

    for (const auto& name : invalidAliases) {
        EXPECT_FALSE(propertySheet()->isValidAlias(name))
            << "\"" << name << "\" was accepted as an alias name, and should not be";
    }
}