pichar and pistring explicit test

This commit is contained in:
2023-07-06 18:37:42 +03:00
parent 3a6b3a4064
commit 8ad2503c5a
6 changed files with 44 additions and 54 deletions

View File

@@ -135,7 +135,7 @@ public:
//! \~russian Возвращает короткий ключ аргумента "name" или пустую строку, если аргумента нет.
PIString argumentShortKey(const PIString & name) {
piForeach(Argument & i, _args)
if (i.name == name) return i.short_key;
if (i.name == name) return PIString(i.short_key);
return PIString();
}

View File

@@ -175,11 +175,11 @@ public:
void setVendorID(ushort vid) {
vid_ = vid;
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
}
void setProductID(ushort pid) {
pid_ = pid;
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
}
bool setConfiguration(uchar value);

View File

@@ -59,7 +59,7 @@ public:
//! \~english Contructs symbol from system locale and no more than 4 bytes of string
//! \~russian Создает символ из системной локали не более 4 байт длины
PIChar(const char * c, int * bytes = 0);
explicit PIChar(const char * c, int * bytes = 0);
//! \~english Copy operator
//! \~russian Оператор присваивания
@@ -81,7 +81,7 @@ public:
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator!=(const PIChar & o) const { return !(o == *this); }
bool operator!=(const PIChar & o) const { return !(*this == o); }
//! \~english Compare operator
//! \~russian Оператор сравнения
@@ -265,36 +265,36 @@ inline bool operator<=(const char * v, const PIChar & c) {
//! \relatesalso PIChar
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator==(const int v, const PIChar & c) {
return (PIChar((ushort)v) == c);
inline bool operator==(ushort v, const PIChar & c) {
return (PIChar(v) == c);
}
//! \relatesalso PIChar
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator>(const int v, const PIChar & c) {
return (PIChar((ushort)v) > c);
inline bool operator>(ushort v, const PIChar & c) {
return (PIChar(v) > c);
}
//! \relatesalso PIChar
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator<(const int v, const PIChar & c) {
return (PIChar((ushort)v) < c);
inline bool operator<(ushort v, const PIChar & c) {
return (PIChar(v) < c);
}
//! \relatesalso PIChar
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator>=(const int v, const PIChar & c) {
return (PIChar((ushort)v) >= c);
inline bool operator>=(ushort v, const PIChar & c) {
return (PIChar(v) >= c);
}
//! \relatesalso PIChar
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator<=(const int v, const PIChar & c) {
return (PIChar((ushort)v) <= c);
inline bool operator<=(ushort v, const PIChar & c) {
return (PIChar(v) <= c);
}
#endif // PICHAR_H

View File

@@ -113,11 +113,11 @@ public:
//! \~english Contructs string with single character "c".
//! \~russian Создает строку из одного символа "c".
PIString(const PIChar c) { d.push_back(c); }
explicit PIString(const PIChar c) { d.push_back(c); }
//! \~english Contructs string with single character "c".
//! \~russian Создает строку из одного символа "c".
PIString(const char c) { d.push_back(PIChar(c)); }
explicit PIString(const char c) { d.push_back(PIChar(c)); }
//! \~english Contructs string from C-string "str" (system codepage).
//! \~russian Создает строку из C-строки "str" (кодировка системы).
@@ -145,7 +145,7 @@ public:
//! \~english Contructs string from byte array "ba" (as UTF-8).
//! \~russian Создает строку из байтового массива "ba" (как UTF-8).
PIString(const PIByteArray & ba) { *this += ba; }
explicit PIString(const PIByteArray & ba) { *this += ba; }
//! \~english Contructs string from "len" characters of buffer "str".
//! \~russian Создает строку из "len" символов массива "str".
@@ -181,7 +181,7 @@ public:
d.push_back(c);
}
PIString(const PIConstChars & c) { *this += c; }
explicit PIString(const PIConstChars & c) { *this += c; }
~PIString();
@@ -1184,15 +1184,6 @@ public:
//! \endcode
int entries(const PIChar c) const;
//! \~english Returns number of occurrences of character "c".
//! \~russian Возвращает число вхождений символа "c".
//! \~\details
//! \~\code
//! piCout << PIString(".str.0").entries('.'); // 2
//! piCout << PIString(".str.0").entries('0'); // 1
//! \endcode
int entries(char c) const { return entries(PIChar(c)); }
//! \~english Returns if string starts with "str".
//! \~russian Возвращает начинается ли строка со "str".
bool startsWith(const PIString & str) const;

View File

@@ -12,7 +12,7 @@ TEST(PIString_Tests, constructor_empty) {
TEST(PIString_Tests, operator_concatenation_pichar) {
PIString str1 = "AB C";
const PIChar str2 = " ";
const PIChar str2 = ' ';
str1 += str2;
PIString res = "AB C ";
ASSERT_EQ(str1, res);
@@ -20,7 +20,7 @@ TEST(PIString_Tests, operator_concatenation_pichar) {
TEST(PIString_Tests, operator_concatenation_pichar_zero1) {
PIString str1 = "";
const PIChar str2 = "D";
const PIChar str2 = 'D';
str1 += str2;
ASSERT_EQ(str1, "D");
}
@@ -120,7 +120,7 @@ TEST(PIString_Tests, construct_pistring) {
TEST(PIString_Tests, construct_pistring_move) {
PIString str1 = "New";
PIString res = str1;
PIString str(move(str1));
PIString str(std::move(str1));
ASSERT_EQ(res, str);
}
@@ -192,14 +192,14 @@ TEST(PIString_Tests, operator_assignment) {
TEST(PIString_Tests, operator_assignment_move) {
PIString str1 = "testing";
PIString str;
str = move(str1);
str = std::move(str1);
ASSERT_EQ(PIString("testing"), str);
ASSERT_TRUE(str1.isEmpty());
}
TEST(PIString_Tests, operator_symbol) {
PIString str1 = "testing";
PIChar symbo = "i";
PIChar symbo = 'i';
ASSERT_EQ(symbo, str1[4]);
}
@@ -217,13 +217,13 @@ TEST(PIString_Tests, operator_equal_pistring_false) {
TEST(PIString_Tests, operator_equal_pichar_true) {
PIString str1 = "t";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_TRUE(str1 == str2);
}
TEST(PIString_Tests, operator_equal_pichar_false) {
PIString str1 = "t";
PIChar str2 = "p";
PIChar str2 = 'p';
ASSERT_FALSE(str1 == str2);
}
@@ -253,13 +253,13 @@ TEST(PIString_Tests, operator_not_equal_pistring_true) {
TEST(PIString_Tests, operator_not_equal_pichar_false) {
PIString str1 = "t";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_FALSE(str1 != str2);
}
TEST(PIString_Tests, operator_not_equal_pichar_true) {
PIString str1 = "t";
PIChar str2 = "p";
PIChar str2 = 'p';
ASSERT_TRUE(str1 != str2);
}
@@ -295,19 +295,19 @@ TEST(PIString_Tests, operator_less_pistring_false_equal) {
TEST(PIString_Tests, operator_less_pichar_true) {
PIString str1 = "a";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_TRUE(str1 < str2);
}
TEST(PIString_Tests, operator_less_pichar_false) {
PIString str1 = "t";
PIChar str2 = "a";
PIChar str2 = 'a';
ASSERT_FALSE(str1 < str2);
}
TEST(PIString_Tests, operator_less_pichar_false_equal) {
PIString str1 = "t";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_FALSE(str1 < str2);
}
@@ -349,19 +349,19 @@ TEST(PIString_Tests, operator_grater_pistring_false_equal) {
TEST(PIString_Tests, operator_grater_pichar_true) {
PIString str1 = "t";
PIChar str2 = "a";
PIChar str2 = 'a';
ASSERT_TRUE(str1 > str2);
}
TEST(PIString_Tests, operator_grater_pichar_false) {
PIString str1 = "a";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_FALSE(str1 > str2);
}
TEST(PIString_Tests, operator_grater_pichar_false_equal) {
PIString str1 = "t";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_FALSE(str1 > str2);
}
@@ -403,19 +403,19 @@ TEST(PIString_Tests, operator_less_eq_pistring_true_equal) {
TEST(PIString_Tests, operator_less_eq_pichar_true) {
PIString str1 = "a";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_TRUE(str1 <= str2);
}
TEST(PIString_Tests, operator_less_eq_pichar_false) {
PIString str1 = "t";
PIChar str2 = "a";
PIChar str2 = 'a';
ASSERT_FALSE(str1 <= str2);
}
TEST(PIString_Tests, operator_less_eq_pichar_true_equal) {
PIString str1 = "t";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_TRUE(str1 <= str2);
}
@@ -457,19 +457,19 @@ TEST(PIString_Tests, operator_grater_eq_pistring_true_equal) {
TEST(PIString_Tests, operator_grater_eq_pichar_true) {
PIString str1 = "t";
PIChar str2 = "a";
PIChar str2 = 'a';
ASSERT_TRUE(str1 >= str2);
}
TEST(PIString_Tests, operator_grater_eq_pichar_false) {
PIString str1 = "a";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_FALSE(str1 >= str2);
}
TEST(PIString_Tests, operator_grater_eq_pichar_true_equal) {
PIString str1 = "t";
PIChar str2 = "t";
PIChar str2 = 't';
ASSERT_TRUE(str1 >= str2);
}

View File

@@ -20,7 +20,6 @@
#include "picli.h"
#include "pidir.h"
#include "piiostream.h"
#include "piprocess.h"
#define DELIM "::"
@@ -251,7 +250,7 @@ void checkQtLib(PIString lib) {
for (int i = 0;; ++i) {
if (qt_deps[i].lib.isEmpty()) break;
if (qt_deps[i].lib == base) {
qt_plugins << qt_deps[i].plugins;
qt_plugins << PISet<PIString>(qt_deps[i].plugins);
// piCout << "add qt plugins" << qt_deps[i].plugins << "now" << qt_plugins;
need_qt = true;
qt_libs << lib;
@@ -269,8 +268,8 @@ void checkQtLib(PIString lib) {
void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
++cur_depth;
if (cur_depth > depth) return;
static PIStringList ignore_ext = {"png", "jpg", "jpeg", "gif", "bmp", "svg", "tif", "tiff", "ico", "pdf",
"txt", "cfg", "conf", "json", "qml", "glsl", "fraq", "vert", "geom", "qmltypes",
static PIStringList ignore_ext = {"png", "jpg", "jpeg", "gif", "bmp", "svg", "tif", "tiff", "ico", "pdf",
"txt", "cfg", "conf", "json", "qml", "glsl", "fraq", "vert", "geom", "qmltypes",
"metainfo", "ts", "qm", "ttf", "htm", "html", "md", "sms", "smsee", "blockmodel"};
PIString ext = PIFile::FileInfo(file).extension();
if (ignore_ext.contains(ext.toLowerCase())) return;
@@ -615,7 +614,7 @@ int main(int argc, char * argv[]) {
out_dir = cli.argumentValue("output");
lib_dirs = cli.argumentValue("search_path").split(DELIM);
add_libs = cli.argumentValue("add_libs").split(DELIM);
ignore_libs = cli.argumentValue("ignore").split(DELIM);
ignore_libs = PISet<PIString>(cli.argumentValue("ignore").split(DELIM));
qt_dir = cli.argumentValue("qtdir");
ldd = cli.argumentValue("ldd");
readelf = cli.argumentValue("Lreadelf");