App: add tests for cell rows and absolute cells

This commit is contained in:
wmayer
2022-10-13 20:16:48 +02:00
parent d5b0dac635
commit 9282fffa07
5 changed files with 198 additions and 4 deletions

View File

@@ -1981,6 +1981,8 @@ void Application::initTypes()
App::FeatureTest ::init();
App::FeatureTestException ::init();
App::FeatureTestColumn ::init();
App::FeatureTestRow ::init();
App::FeatureTestAbsAddress ::init();
App::FeatureTestPlacement ::init();
App::FeatureTestAttribute ::init();

View File

@@ -219,6 +219,42 @@ DocumentObjectExecReturn *FeatureTestColumn::execute()
// ----------------------------------------------------------------------------
PROPERTY_SOURCE(App::FeatureTestRow, App::DocumentObject)
FeatureTestRow::FeatureTestRow()
{
ADD_PROPERTY_TYPE(Row, ("1"), "Test", App::Prop_None, "");
ADD_PROPERTY_TYPE(Silent, (false), "Test", App::Prop_None, "");
ADD_PROPERTY_TYPE(Value, (0L), "Test", App::Prop_Output, "");
}
DocumentObjectExecReturn *FeatureTestRow::execute()
{
Value.setValue(decodeRow(Row.getStrValue(), Silent.getValue()));
return nullptr;
}
// ----------------------------------------------------------------------------
PROPERTY_SOURCE(App::FeatureTestAbsAddress, App::DocumentObject)
FeatureTestAbsAddress::FeatureTestAbsAddress()
{
ADD_PROPERTY_TYPE(Address, (""), "Test", Prop_None, "");
ADD_PROPERTY_TYPE(Valid, (false), "Test", PropertyType(Prop_Output | Prop_ReadOnly), "");
}
DocumentObjectExecReturn *FeatureTestAbsAddress::execute()
{
CellAddress address;
Valid.setValue(address.parseAbsoluteAddress(Address.getValue()));
return StdReturn;
}
// ----------------------------------------------------------------------------
PROPERTY_SOURCE(App::FeatureTestPlacement, App::DocumentObject)

View File

@@ -153,6 +153,36 @@ public:
//@}
};
class FeatureTestRow : public DocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(App::FeatureTestRow);
public:
FeatureTestRow();
// Standard Properties (PropertyStandard.h)
App::PropertyString Row;
App::PropertyBool Silent;
App::PropertyInteger Value;
/** @name methods override Feature */
//@{
DocumentObjectExecReturn *execute() override;
//@}
};
class FeatureTestAbsAddress : public DocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(App::FeatureTestAbsAddress);
public:
FeatureTestAbsAddress();
DocumentObjectExecReturn *execute() override;
App::PropertyString Address;
App::PropertyBool Valid;
};
class FeatureTestPlacement : public DocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(App::FeatureTestPlacement);

View File

@@ -30,6 +30,7 @@
#include <regex>
#endif
#include <string_view>
#include <Base/Exception.h>
#include "Range.h"
@@ -39,6 +40,18 @@ using namespace App;
const int App::CellAddress::MAX_ROWS = 16384;
const int App::CellAddress::MAX_COLUMNS = 26 * 26 + 26;
namespace App {
// From a given cell address the '$' must be at within the first
// few characters
bool maybeAbsolute(std::string_view address)
{
const int MAX_COLUMNS_LETTERS = 2;
address = address.substr(0, MAX_COLUMNS_LETTERS + 1);
return address.find("$") != std::string_view::npos;
}
}
Range::Range(const char * range, bool normalize)
{
std::string from;
@@ -271,10 +284,16 @@ std::string App::CellAddress::toString(Cell cell) const
return s.str();
}
bool App::CellAddress::parseAbsoluteAddress(const char *txt) {
if(txt[0]=='$' || (txt[0] && txt[1] && (txt[1]=='$' || txt[2]=='$'))) {
CellAddress addr = stringToAddress(txt,true);
if(addr.isValid()) {
/*!
* \brief App::CellAddress::parseAbsoluteAddress
* \param address
* If the passed string is a valid and absolute cell address it will be assigned to this instance.
* \return True if it's an absolute cell address and false otherwise
*/
bool App::CellAddress::parseAbsoluteAddress(const char *address) {
if (maybeAbsolute(address)) {
CellAddress addr = stringToAddress(address, true);
if (addr.isValid()) {
*this = addr;
return true;
}