Commit 1c127fd643e212e7f4860cfc1735e510f5cc72a3
1 parent
91353399
Exists in
master
Inclusão do teste e dos métodos:
-getValueFromTags -getValueFromFile -setValueToFile -createFolder -deleteFolder -deleteFile
Showing
4 changed files
with
108 additions
and
24 deletions
Show diff stats
cacic-teste/testcacic.cpp
... | ... | @@ -14,8 +14,8 @@ CTestCacic::CTestCacic(QObject *parent) : |
14 | 14 | "1", |
15 | 15 | "0", |
16 | 16 | "0", |
17 | - "YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
18 | - "8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
17 | + /*QDir::currentPath(), */"YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
18 | + /*QTest::currentAppName(), */"8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
19 | 19 | "wshPlZWvLPhbUEQFQ1aQmA==__CRYPTED__", |
20 | 20 | "E9aKtVz/OSmGv7v1xW4FwaFukOob3qQ/HFDIz916K3ys82qfX9vBDz[[MAIS]]M2cdoYedhNkXt[[MAIS]]UVb10nD[[MAIS]]tOfbn7mlOlTDoGzUl9CgdPCsb[[MAIS]]Qa4wzuCrMw0BcCuaKfr62E3b8vh6Ug4JJbOgBo3ohG3x5O7Ap0D94GKtAWjMuTXRBbhGxPrRS4M6AhzvaN5P8pWd9FikrCLWuMs4ebnRlftef3RmVKScBDQ5zmK6sKxYNmX[[MAIS]]kKn/Gi2[[MAIS]]HftZ7HD9JLvZBpYhp4yjqShblQ67d6PlWgrRWXxwDseIiJe3NlF70zrCPBBelkeAhVDXMXnsYtLms3ElsLzxa3c5vpWzTfgyE[[MAIS]]hvALy4ivew7zaxEwrg2KY1T7GOSWZ7vljIvbhVZJgtzbnYiulFjJTtm5W4uJMKLuUJNzB0rxMkzToIE9/kDmeO2OKiwFbIfbe2Wdq0VpllOkjKtj9WM676iBSpYAXG0MsmLMj9CZ/sNi06hGF[[MAIS]]rXxiOSk66M0Hq[[MAIS]]OeUBh4z3Ra6f9yPJn0K9hIQyT[[MAIS]]Dr/QW/QdJIOkLTW8ZyyAF4DW9ojiTlUdySvB5EB1jyZ5nNTpzyE38qIdg7uM1tdWdm9FZGYxMdHwi1tS2dBeIWkDfWEjih01xiVt2dmdRgo0zIZvmmYDJ9LhCU3XPDlwdeQ8[[MAIS]]F7fnxDfxGqZQjZJ[[MAIS]]Y/Q8bdLpgbhcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__", |
21 | 21 | "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__", |
... | ... | @@ -23,8 +23,26 @@ CTestCacic::CTestCacic(QObject *parent) : |
23 | 23 | "2.5.1.1.256.32", |
24 | 24 | "2.8.1.7", |
25 | 25 | "2.8.1.6"); |
26 | + testPath = QDir::currentPath() + "/teste"; | |
27 | + testIniPath = testPath + "/teste.ini"; | |
26 | 28 | } |
27 | 29 | |
30 | +void CTestCacic::testCreateFolder() | |
31 | +{ | |
32 | + QVERIFY(OCacic.createFolder(testPath)); | |
33 | +} | |
34 | + | |
35 | +void CTestCacic::testGetAndSetValueFromFile() | |
36 | +{ | |
37 | + OCacic.setValueToFile("Teste", "teste", "Valor de teste", testIniPath); | |
38 | + QVERIFY( OCacic.getValueFromFile("Teste", "teste", testIniPath) == "Valor de teste"); | |
39 | +} | |
40 | + | |
41 | +void CTestCacic::testGetValueFromTags() | |
42 | +{ | |
43 | + QString value = "blablab[teste]Valor de teste[/teste]feihgj"; | |
44 | + QVERIFY(OCacic.getValueFromTags(value, "teste") == "Valor de teste"); | |
45 | +} | |
28 | 46 | |
29 | 47 | void CTestCacic::testCommStatus() |
30 | 48 | { |
... | ... | @@ -34,21 +52,18 @@ void CTestCacic::testCommStatus() |
34 | 52 | void CTestCacic::testComm() |
35 | 53 | { |
36 | 54 | |
37 | - if (OCacicComm.commStatus()) | |
38 | - QVERIFY(OCacicComm.comm("/ws/get/test") != QString("")); | |
39 | - else | |
55 | + if (OCacicComm.commStatus()){ | |
56 | + QVERIFY(OCacic.getValueFromTags(OCacicComm.comm("/ws/get/test"), "Comm_Status", "<>") == QString("OK")); | |
57 | + } else | |
40 | 58 | QSKIP("Teste de comunicação negativo!"); |
41 | 59 | } |
42 | 60 | |
43 | -void CTestCacic::testGetValueFromFile() | |
61 | +void CTestCacic::testDeleteFile() | |
44 | 62 | { |
45 | - QVERIFY( OCacic.getValueFromFile("Teste", "teste","E:/teste.txt") == "Valor de teste"); | |
63 | + QVERIFY(OCacic.deleteFile(testIniPath)); | |
46 | 64 | } |
47 | 65 | |
48 | -void CTestCacic::testGetValueFromTags() | |
66 | +void CTestCacic::testDeleteFolder() | |
49 | 67 | { |
50 | - QString value = "blablab[teste]Valor de teste[/teste]feihgj"; | |
51 | - QString retorno = OCacic.getValueFromTags(value, "teste"); | |
52 | - qDebug(retorno.toLocal8Bit()); | |
53 | - QVERIFY(retorno == "Valor de teste"); | |
68 | + QVERIFY(OCacic.deleteFolder(testPath)); | |
54 | 69 | } | ... | ... |
cacic-teste/testcacic.h
... | ... | @@ -14,6 +14,8 @@ public: |
14 | 14 | private: |
15 | 15 | CacicComm OCacicComm; |
16 | 16 | CCacic OCacic; |
17 | + QString testPath; | |
18 | + QString testIniPath; | |
17 | 19 | |
18 | 20 | signals: |
19 | 21 | |
... | ... | @@ -22,8 +24,11 @@ public slots: |
22 | 24 | private slots: |
23 | 25 | void testCommStatus(); |
24 | 26 | void testComm(); |
25 | - void testGetValueFromFile(); | |
27 | + void testGetAndSetValueFromFile(); | |
26 | 28 | void testGetValueFromTags(); |
29 | + void testCreateFolder(); | |
30 | + void testDeleteFolder(); | |
31 | + void testDeleteFile(); | |
27 | 32 | }; |
28 | 33 | |
29 | 34 | #endif // TESTINSTALLCACIC_H | ... | ... |
src/ccacic.cpp
... | ... | @@ -4,35 +4,61 @@ CCacic::CCacic(QObject *parent) : |
4 | 4 | QObject(parent) |
5 | 5 | { |
6 | 6 | } |
7 | - | |
7 | +/* getValueFromFile | |
8 | + * Pega valor específico dentro de um arquivo | |
9 | + * @parameter QString sectionName: nome da seção onde estará a key) | |
10 | + * @parameter QString keyName: nome da key que está o valor) | |
11 | + * @parameter QString filePath: caminho do arquivo que será aberto; | |
12 | + * | |
13 | + * @return QString: "" (vazio) Caso não encontre, | |
14 | + * "0" caso não seja possível abrir o arquivo; | |
15 | + */ | |
8 | 16 | QString CCacic::getValueFromFile(QString sectionName, QString keyName, QString filePath) |
9 | 17 | { |
10 | 18 | QFile file(filePath); |
11 | - sectionName = "<" + sectionName + ">"; | |
19 | + QString line = ""; | |
20 | + sectionName = "[" + sectionName + "]"; | |
12 | 21 | keyName = keyName + "="; |
13 | 22 | int sizeKeyName = keyName.size(); |
14 | 23 | |
15 | 24 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
16 | 25 | return "0"; |
17 | - | |
18 | - QString line = file.readLine(); | |
19 | - while (!file.atEnd()) { | |
26 | + while (!file.atEnd()){ | |
27 | + line = file.readLine(); | |
20 | 28 | if (line.contains(sectionName, Qt::CaseInsensitive)) { |
21 | - line = file.readLine(); | |
22 | - while (!file.atEnd()){ | |
29 | + do { | |
30 | + line = file.readLine(); | |
23 | 31 | if (line.contains(keyName, Qt::CaseInsensitive)) { |
24 | 32 | file.close(); |
25 | 33 | return line.mid(sizeKeyName).trimmed(); |
26 | 34 | } |
27 | - } | |
28 | - } else { | |
29 | - line = file.readLine(); | |
35 | + } while (!file.atEnd()); | |
30 | 36 | } |
31 | 37 | } |
32 | 38 | file.close(); |
33 | 39 | return ""; |
34 | 40 | } |
41 | +/*getValueFromTags | |
42 | + * @parameter QString sectionName: Grupo onde está a chave; | |
43 | + * @parameter QString keyName: chave que queremos para colocar o valor; | |
44 | + * @parameter QString value: valor para colocar dentro da chave; | |
45 | + * @parameter QString filePath: Local do arquivo; | |
46 | + */ | |
47 | +void CCacic::setValueToFile(QString sectionName, QString keyName, QString value, QString filePath) | |
48 | +{ | |
49 | + QSettings settings(filePath, QSettings::IniFormat); | |
50 | + settings.beginGroup(sectionName); | |
51 | + settings.setValue(keyName, value); | |
52 | + settings.endGroup(); | |
53 | +} | |
35 | 54 | |
55 | +/*getValueFromTags | |
56 | + * @parameter QString fullString: string onde será pesquisado o valor desejado; | |
57 | + * @parameter QString tag: nome da tag onde estará o valor; | |
58 | + * @parameter QString tagType: padrão "[]", tipo da tag; | |
59 | + * | |
60 | + * @return: QString: valor entre as tags. | |
61 | + */ | |
36 | 62 | QString CCacic::getValueFromTags(QString fullString, QString tag, QString tagType) { |
37 | 63 | QString tagFim = tagType.mid(0,1) + "/" + tag + tagType.mid(1); |
38 | 64 | int tagSize; |
... | ... | @@ -41,6 +67,39 @@ QString CCacic::getValueFromTags(QString fullString, QString tag, QString tagTyp |
41 | 67 | return fullString.mid(fullString.indexOf(tag) + tagSize, |
42 | 68 | fullString.indexOf(tagFim) - (fullString.indexOf(tag) + tagSize)).trimmed(); |
43 | 69 | } |
70 | +/*createFolder | |
71 | + * @parameter QString path: caminho onde será criado o diretório, sendo criado toda a árvore se necessário. | |
72 | + * @return bool: true se conseguir ou já existir, false se não. | |
73 | + */ | |
74 | +bool CCacic::createFolder(QString path) | |
75 | +{ | |
76 | + QDir folder(path); | |
77 | + return folder.mkpath(path); | |
78 | +} | |
79 | +/*deleteFolder | |
80 | + * @parameter QString path: caminho do diretório; | |
81 | + * @return bool: true se conseguir ou já não existir, false se não conseguir. | |
82 | + */ | |
83 | +bool CCacic::deleteFolder(QString path) | |
84 | +{ | |
85 | + QDir folder(path); | |
86 | + if (folder.exists()) | |
87 | + return folder.removeRecursively(); | |
88 | + else | |
89 | + return true; | |
90 | +} | |
91 | +/*deleteFile | |
92 | + * @parameter QString path: caminho do arquivo; | |
93 | + * @return bool: true se conseguir ou já não existir, false se não conseguir. | |
94 | + */ | |
95 | +bool CCacic::deleteFile(QString path) | |
96 | +{ | |
97 | + QDir folder(path); | |
98 | + if (folder.exists()) | |
99 | + return folder.remove(path); | |
100 | + else | |
101 | + return true; | |
102 | +} | |
44 | 103 | |
45 | 104 | /*Getters/Setters |
46 | 105 | * Begin: | ... | ... |
src/ccacic.h
... | ... | @@ -5,7 +5,8 @@ |
5 | 5 | #include <QObject> |
6 | 6 | #include <QDebug> |
7 | 7 | #include <QFile> |
8 | -#include <iostream> | |
8 | +#include <QSettings> | |
9 | +#include <QDir> | |
9 | 10 | |
10 | 11 | class CCacic : public QObject |
11 | 12 | { |
... | ... | @@ -13,7 +14,11 @@ class CCacic : public QObject |
13 | 14 | public: |
14 | 15 | explicit CCacic(QObject *parent = 0); |
15 | 16 | QString getValueFromFile(QString sectionName, QString keyName, QString filePath); |
17 | + void setValueToFile(QString sectionName, QString keyName, QString value, QString filePath); | |
16 | 18 | QString getValueFromTags(QString fullString, QString tag, QString tagType = "[]"); |
19 | + bool createFolder(QString path); | |
20 | + bool deleteFolder(QString path); | |
21 | + bool deleteFile(QString path); | |
17 | 22 | |
18 | 23 | //Geters/seters: |
19 | 24 | ... | ... |