Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 448
Merged at revision: 456
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-16
Diff against target: 706 lines (+681/-0)
2 files modified
src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp (+658/-0)
src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h (+23/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+265216@code.launchpad.net

Commit message

Created Unit Tests for Samba Similar Qt Objects: SmbLocationItemFile, SmbLocationItemDir and SmbLocationItemDirIterator

Description of the change

Created Unit Tests for Samba Similar Qt Objects in "qsambaclient" module.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:44:54 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:44:54 +0000
@@ -26,6 +26,8 @@
26#include "locationurl.h"26#include "locationurl.h"
27#include "smbutil.h"27#include "smbutil.h"
28#include "smblocationdiriterator.h"28#include "smblocationdiriterator.h"
29#include "smblocationitemfile.h"
30#include "smblocationitemdir.h"
29#include <sys/stat.h>31#include <sys/stat.h>
30#include <errno.h>32#include <errno.h>
3133
@@ -726,3 +728,659 @@
726 }728 }
727 return true;729 return true;
728}730}
731
732
733void TestQSambaSuite::unit_QFile_rename()
734{
735 ShareCreationStatus share(createTempShare("unit_QFile_rename"));
736 if (share.tempDir)
737 {
738 share.tempDir->setAutoRemove(true);
739 }
740 QCOMPARE(share.status, true);
741
742 //negative tests
743 //empty object
744 SmbLocationItemFile fileNameEmptyDoesNotExist;
745 QString newName("this_was_renamed.txt");
746 QCOMPARE(fileNameEmptyDoesNotExist.rename(newName), false);
747 QCOMPARE(fileNameEmptyDoesNotExist.rename(QLatin1String(0), newName), false);
748 //orig file does not exist
749 QString nameDoesNotExist("_it_must_not_exist");
750 SmbSharedPathAccess item = share.createPathForItem(nameDoesNotExist);
751 QFileInfo diskFileContent(item.diskPathname);
752 QCOMPARE(diskFileContent.exists(), false);
753 SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
754 QCOMPARE(fileNameDoesNotExist.rename(newName), false);
755 QCOMPARE(fileNameDoesNotExist.rename(nameDoesNotExist, newName), false);
756
757 //positive tests
758 SmbSharedPathAccess newItem = share.createPathForItem(newName);
759 QFileInfo newFileInfo(newItem.diskPathname);
760 //make sure target does not exist
761 QCOMPARE(newFileInfo.exists(), false);
762 //now rename
763 SmbLocationItemFile fileNameExists(share.fileContent.smbUrl);
764 QCOMPARE(fileNameExists.rename(newItem.smbUrl), true);
765 //now target must exist in local file system
766 QCOMPARE(newFileInfo.exists(), true);
767 diskFileContent.setFile(share.fileContent.diskPathname);
768 //make sure orignal file no longer exist
769 QCOMPARE(diskFileContent.exists(), false);
770 //now back to original name using an empty object
771 SmbLocationItemFile empty;
772 QCOMPARE(empty.rename(newItem.smbUrl, share.fileContent.smbUrl), true);
773 //make sure orignal exists again
774 QCOMPARE(diskFileContent.exists(), true);
775}
776
777
778void TestQSambaSuite::unit_QFile_remove()
779{
780 ShareCreationStatus share(createTempShare("unit_QFile_remove"));
781 if (share.tempDir)
782 {
783 share.tempDir->setAutoRemove(true);
784 }
785 QCOMPARE(share.status, true);
786
787 //negative tests
788 //empty object
789 SmbLocationItemFile fileNameEmptyDoesNotExist;
790 QCOMPARE(fileNameEmptyDoesNotExist.remove(), false);
791 //file name does not exist
792 SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
793 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
794 SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
795 QCOMPARE(fileNameDoesNotExist.remove(), false);
796 QFileInfo diskFileInfo(share.fileContent.diskPathname);
797// //now try to remove a file which does not have write permission
798// QCOMPARE(diskFileInfo.exists(), true);
799// QFile::Permissions originalPermissions = diskFileInfo.permissions();
800// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther), true);
801// SmbLocationItemFile existentFileButNoWritePermission(share.fileContent.smbUrl);
802// //remove must fail
803// QCOMPARE(existentFileButNoWritePermission.remove(), false);
804// QCOMPARE(errno, EPERM);
805// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, originalPermissions), true);
806
807 //positive test, remove fileContent
808 SmbLocationItemFile existentFile(share.fileContent.smbUrl);
809 SmbItemInfo smbExistentItem(share.fileContent.smbUrl);
810 QCOMPARE(smbExistentItem.exists(), true);
811 QCOMPARE(existentFile.remove(), true);
812 SmbItemInfo smbItem(share.fileContent.smbUrl);
813 //samba url for this file must not exist
814 QCOMPARE(smbItem.exists(), false);
815 //now origin file in file system must no longer exist
816 QCOMPARE(diskFileInfo.exists(), false);
817}
818
819
820void TestQSambaSuite::unit_QFile_open()
821{
822 ShareCreationStatus share(createTempShare("unit_QFile_open"));
823 if (share.tempDir)
824 {
825 share.tempDir->setAutoRemove(true);
826 }
827 QCOMPARE(share.status, true);
828
829 //negative tests
830 SmbLocationItemFile fileNameEmptyDoesNotExist;
831 QCOMPARE(fileNameEmptyDoesNotExist.open(QFile::WriteOnly), false);
832 SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
833 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
834 SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
835 QCOMPARE(fileNameDoesNotExist.open(QFile::ReadOnly), false);
836
837 // ---- positive tests
838 //create a smb file using open
839 item = share.createPathForItem("now_it_must_be_created");
840 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
841 SmbLocationItemFile fileCreated(item.smbUrl);
842 QCOMPARE(fileCreated.open(QFile::WriteOnly), true);
843 if (QFileInfo(item.diskPathname).exists() == false)
844 {
845 fileCreated.close(); // force to close if necessary
846 }
847 QCOMPARE(fileCreated.isOpen(), true);
848 //now check in the local disk to see if it was really created
849 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
850 //as QFile it closes itself in the destructor
851}
852
853
854void TestQSambaSuite::unit_QFile_read()
855{
856 ShareCreationStatus share(createTempShare("unit_QFile_read"));
857 if (share.tempDir)
858 {
859 share.tempDir->setAutoRemove(true);
860 }
861 QCOMPARE(share.status, true);
862
863 //negative tests
864 SmbLocationItemFile fileNameEmptyDoesNotExist;
865 char buffer[100];
866
867 //get Qt read return when there is no file
868 qint64 qt_read_no_file = QFile().read(buffer, sizeof(buffer));
869
870 QCOMPARE(fileNameEmptyDoesNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
871 SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
872 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
873 SmbLocationItemFile fileMustNotExist(item.smbUrl);
874 QCOMPARE(fileMustNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
875
876 //positive test
877 //create a file in the local folder which is shared by Samba
878 item = share.createPathForItem("created_in_the_disk.txt");
879 QFile inDisk(item.diskPathname);
880 QCOMPARE(inDisk.open(QFile::WriteOnly), true);
881 QByteArray diskContent("This a simple content used to test reading files from samba: ");
882 QByteArray initialDiskContent(diskContent);
883 QByteArray moreDiskContent(100, 'a');
884 diskContent += moreDiskContent;
885 QCOMPARE(inDisk.write(diskContent), (qint64)diskContent.size());
886 inDisk.close();
887 //now read from Samba
888 SmbLocationItemFile existentFile(item.smbUrl);
889 QCOMPARE(existentFile.open(QFile::ReadOnly), true);
890 char smbBuffer [diskContent.size() + 100];
891 //before first read
892 QCOMPARE(existentFile.atEnd(), false);
893 qint64 bytesRead = existentFile.read(smbBuffer, (qint64)initialDiskContent.size());
894 qint64 expectedRead = (qint64)initialDiskContent.size();
895 QCOMPARE(bytesRead, expectedRead);
896 QByteArray smbContent(smbBuffer,initialDiskContent.size());
897 //compare the intial content
898 QCOMPARE(smbContent, initialDiskContent);
899 //before second read
900 QCOMPARE(existentFile.atEnd(), false);
901 expectedRead = (qint64) (diskContent.size() - initialDiskContent.size());
902 //read remaining data in the file
903 bytesRead = existentFile.read(smbBuffer, expectedRead);
904 QCOMPARE(bytesRead, expectedRead);
905 QByteArray moreSmbContent(smbBuffer, expectedRead);
906 smbContent += moreSmbContent;
907 //now compare the whole content
908 QCOMPARE(smbContent, diskContent);
909 //now atEnd() must be true
910 QCOMPARE(existentFile.atEnd(), true);
911}
912
913
914void TestQSambaSuite::unit_QFile_write()
915{
916 ShareCreationStatus share(createTempShare("unit_QFile_write"));
917 if (share.tempDir)
918 {
919 share.tempDir->setAutoRemove(true);
920 }
921 QCOMPARE(share.status, true);
922
923 //negative tests
924 SmbLocationItemFile fileNameEmptyDoesNotExist;
925 QByteArray someContent("This is a simple content\n");
926 //get Qt write return when there is no file
927 qint64 qt_write_no_file = QFile().write(someContent.constData(), (qint64)someContent.size());
928 QCOMPARE(fileNameEmptyDoesNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
929 SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
930 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
931 SmbLocationItemFile fileMustNotExist(item.smbUrl);
932 QCOMPARE(fileMustNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
933
934 //positive tests
935 //work with 2 items saving in Samba and saving in local file system
936 SmbSharedPathAccess items[2];
937 items[0] = share.createPathForItem("first_item.txt");
938 items[1] = share.createPathForItem("second_item.txt");
939 QByteArray content; // starts empty
940 QFile::OpenMode openMode = QFile::WriteOnly; //after first write it receives Append mode
941 const int diskIndex = 0;
942 const int smbindex = 1;
943 QByteArray savedContent;
944 for(int counter = 0; counter < 4; ++counter, content += someContent)
945 {
946 QFile diskFile(items[diskIndex].diskPathname);
947 SmbLocationItemFile smbFile(items[smbindex].smbUrl);
948 //open both files
949 QCOMPARE(diskFile.open(openMode), true);
950 QCOMPARE(smbFile.open(openMode), true);
951 //first write should return 0 as content is empty
952 qint64 toSave = content.size();
953 qint64 wrote = diskFile.write(content.constData(), toSave);
954 QCOMPARE(wrote, toSave);
955 wrote = smbFile.write(content.constData(), toSave);
956 QCOMPARE(wrote, toSave);
957 savedContent += content;
958 diskFile.close();
959 smbFile.close();
960 if (counter > 0)
961 {
962 openMode = QFile::Append;
963 }
964 }
965 //now check size and content
966 QFile diskFile(items[diskIndex].diskPathname);
967 SmbLocationItemFile smbFile(items[smbindex].smbUrl);
968 QCOMPARE(smbFile.size(), diskFile.size());
969 QCOMPARE(diskFile.open(QFile::ReadOnly), true);
970 QCOMPARE(smbFile.open(QFile::ReadOnly), true);
971 //read file from disk, check the content
972 char buffer [1024];
973 qint64 gotBytes = diskFile.read(buffer, sizeof(buffer));
974 QCOMPARE((qint64)savedContent.size(), gotBytes);
975 QByteArray otherContent(buffer, (int)gotBytes);
976 QCOMPARE(otherContent, savedContent);
977 //read SMB file from disk, check the content
978 gotBytes = smbFile.read(buffer, sizeof(buffer));
979 QCOMPARE((qint64)savedContent.size(), gotBytes);
980 otherContent.setRawData(buffer, (int)gotBytes);
981 QCOMPARE(otherContent, savedContent);
982}
983
984
985void TestQSambaSuite::unit_QFile_atEnd()
986{
987 ShareCreationStatus share(createTempShare("unit_QFile_atEnd"));
988 if (share.tempDir)
989 {
990 share.tempDir->setAutoRemove(true);
991 }
992 QCOMPARE(share.status, true);
993
994 //negative tests
995 SmbLocationItemFile fileNameEmptyDoesNotExist;
996 QCOMPARE(fileNameEmptyDoesNotExist.atEnd(), true);
997 SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
998 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
999 SmbLocationItemFile fileMustNotExist(item.smbUrl);
1000 QCOMPARE(fileMustNotExist.atEnd(), true);
1001 QFileInfo fileContentInfo(share.fileContent.diskPathname);
1002 QCOMPARE(fileContentInfo.exists(), true);
1003 SmbLocationItemFile existentFile(share.fileContent.smbUrl);
1004 //first at end when file is still closed
1005 QCOMPARE(existentFile.atEnd(), true);
1006 QCOMPARE(existentFile.open(QFile::ReadOnly), true);
1007 char buffer [fileContentInfo.size()];
1008 QCOMPARE(existentFile.read(buffer, (qint64)10), (qint64)10);
1009 //file is opened and not at end
1010 QCOMPARE(existentFile.atEnd(), false);
1011 QVERIFY(existentFile.read(buffer, fileContentInfo.size()) > 0);
1012 QCOMPARE(existentFile.atEnd(), true);
1013}
1014
1015
1016void TestQSambaSuite::unit_QFile_size()
1017{
1018 ShareCreationStatus share(createTempShare("unit_QFile_size"));
1019 if (share.tempDir)
1020 {
1021 share.tempDir->setAutoRemove(true);
1022 }
1023 QCOMPARE(share.status, true);
1024
1025 //negative tests
1026 //empty objects
1027 qint64 qFile_size_for_disk = QFileInfo().size();
1028 SmbLocationItemFile fileNameEmptyDoesNotExist;
1029 QCOMPARE(fileNameEmptyDoesNotExist.size(), qFile_size_for_disk);
1030 //file does not exist
1031 SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
1032 QFileInfo diskFileInfo(item.diskPathname);
1033 QCOMPARE(diskFileInfo.exists(), false);
1034 qFile_size_for_disk = diskFileInfo.size();
1035 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1036 SmbLocationItemFile fileMustNotExist(item.smbUrl);
1037 QCOMPARE(fileMustNotExist.size(), qFile_size_for_disk);
1038
1039 //positive tests
1040 diskFileInfo.setFile(share.fileContent.diskPathname);
1041 QCOMPARE(diskFileInfo.exists(), true);
1042 qFile_size_for_disk = diskFileInfo.size();
1043 QVERIFY(qFile_size_for_disk > 0);
1044 SmbLocationItemFile existentFile(share.fileContent.smbUrl);
1045 //first time the file is closed
1046 QCOMPARE(existentFile.size(), qFile_size_for_disk);
1047 QCOMPARE(existentFile.open(QFile::ReadOnly), true);
1048 //second time the file is opened
1049 QCOMPARE(existentFile.size(), qFile_size_for_disk);
1050 //now append data using local file system
1051 QFile moreDataFile(share.fileContent.diskPathname);
1052 QCOMPARE(moreDataFile.open(QFile::Append), true);
1053 QByteArray moreData("just a more bytes");
1054 QCOMPARE(moreDataFile.write(moreData), (qint64)moreData.size());
1055 moreDataFile.close();
1056 //other QFileInfo object to get new information
1057 QFileInfo newDiskFileInfo(share.fileContent.diskPathname);
1058 QVERIFY(newDiskFileInfo.size() > qFile_size_for_disk); // has more data now
1059 QCOMPARE(existentFile.size(), newDiskFileInfo.size());
1060}
1061
1062
1063void TestQSambaSuite::unit_QFile_isOpen()
1064{
1065 ShareCreationStatus share(createTempShare("unit_QFile_isOpen"));
1066 if (share.tempDir)
1067 {
1068 share.tempDir->setAutoRemove(true);
1069 }
1070 QCOMPARE(share.status, true);
1071
1072 //negative tests
1073 SmbLocationItemFile fileNameEmptyDoesNotExist;
1074 QCOMPARE(fileNameEmptyDoesNotExist.isOpen(), false);
1075 SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
1076 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1077 SmbLocationItemFile fileMustNotExist(item.smbUrl);
1078 QCOMPARE(fileMustNotExist.isOpen(), false);
1079
1080 //positive tests
1081 SmbLocationDirIterator fileContentIterator(share.url, QDir::Files);
1082 QCOMPARE(fileContentIterator.hasNext(), true);
1083 fileContentIterator.next();
1084 DirItemInfo iteminfo = fileContentIterator.fileInfo();
1085 QCOMPARE(iteminfo.exists(), true);
1086 SmbLocationItemFile smbFile(iteminfo.urlPath());
1087 QCOMPARE(smbFile.isOpen(), false);
1088 QCOMPARE(smbFile.open(QFile::ReadOnly), true);
1089 QCOMPARE(smbFile.isOpen(), true);
1090}
1091
1092
1093void TestQSambaSuite::unit_QFile_permissions()
1094{
1095 ShareCreationStatus share(createTempShare("unit_QFile_permissions"));
1096 if (share.tempDir)
1097 {
1098 share.tempDir->setAutoRemove(true);
1099 }
1100 QCOMPARE(share.status, true);
1101
1102 //negative tests
1103 //empty objects
1104 QFile::Permissions qt_empty_permissions = QFileInfo().permissions();
1105 SmbLocationItemFile fileNameEmptyDoesNotExist;
1106 QCOMPARE(fileNameEmptyDoesNotExist.permissions(), qt_empty_permissions);
1107 //file does not exist
1108 SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
1109 QFileInfo diskFileInfo(item.diskPathname);
1110 QCOMPARE(diskFileInfo.exists() ,false);
1111 SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
1112 QCOMPARE(fileNameDoesNotExist.permissions(), qt_empty_permissions);
1113
1114 //positive test, change in the local disk , check for permission in Samba
1115 QFile::Permissions perm_readOnly = QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser;
1116
1117 QFileInfo diskExistentFile(share.fileContent.diskPathname);
1118 QCOMPARE(diskExistentFile.exists(), true);
1119 //first make sure permissions are different
1120 QVERIFY(diskExistentFile.permissions() != perm_readOnly);
1121 //set permission using file in the local file system
1122 QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, perm_readOnly), true);
1123 //check the permission in the local file system
1124 QTest::qWait(100);
1125 QFile::Permissions curr_permissions = QFile(share.fileContent.diskPathname).permissions();
1126 QCOMPARE(curr_permissions, perm_readOnly);
1127 //now the same permission must come using Samba
1128 SmbLocationItemFile smbExistentFile(share.fileContent.smbUrl);
1129 QFile::Permissions curr_smb_ermissions = smbExistentFile.permissions();
1130 QCOMPARE(curr_smb_ermissions, perm_readOnly);
1131}
1132
1133
1134void TestQSambaSuite::unit_QFile_setPermissions()
1135{
1136 ShareCreationStatus share(createTempShare("unit_QFile_setPermissions"));
1137 if (share.tempDir)
1138 {
1139 share.tempDir->setAutoRemove(true);
1140 }
1141 QCOMPARE(share.status, true);
1142
1143 //negative tests
1144 //empty objects
1145 QFile::Permissions qt_permissions = QFile::ReadOwner | QFile::ReadUser | QFile::WriteOwner | QFile::WriteUser;
1146 SmbLocationItemFile fileNameEmptyDoesNotExist;
1147 QCOMPARE(fileNameEmptyDoesNotExist.setPermissions(qt_permissions), false);
1148 //file does not exist
1149 SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
1150 QFileInfo diskFileInfo(item.diskPathname);
1151 QCOMPARE(diskFileInfo.exists() ,false);
1152 SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
1153 QCOMPARE(fileNameDoesNotExist.setPermissions(qt_permissions), false);
1154
1155 QCOMPARE(fileNameDoesNotExist.setPermissions(share.fileContent.smbUrl, qt_permissions), true);
1156 SmbLocationItemFile smbFile(share.fileContent.smbUrl);
1157 QCOMPARE(smbFile.setPermissions(qt_permissions), true);
1158}
1159
1160
1161void TestQSambaSuite::unit_QDir_exists()
1162{
1163 ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
1164 if (share.tempDir)
1165 {
1166 share.tempDir->setAutoRemove(true);
1167 }
1168 QCOMPARE(share.status, true);
1169
1170 //negative tests
1171 SmbLocationItemDir directoryEmptyName;
1172 QCOMPARE(directoryEmptyName.exists(), false);
1173 SmbSharedPathAccess item = share.createPathForItem("dirName");
1174 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1175 SmbLocationItemDir directoryDoesNotExist(item.smbUrl);
1176 QCOMPARE(directoryDoesNotExist.exists(), false);
1177
1178 //positve test
1179 //item.smbUrl does not exist, check above
1180 //create it in the disk
1181 QCOMPARE(QDir().mkpath(item.diskPathname), true);
1182 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1183 SmbLocationItemDir directoyExists(item.smbUrl);
1184 QCOMPARE(directoyExists.exists(), true);
1185}
1186
1187
1188
1189
1190void TestQSambaSuite::unit_QDir_mkdir()
1191{
1192 ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
1193 if (share.tempDir)
1194 {
1195 share.tempDir->setAutoRemove(true);
1196 }
1197 QCOMPARE(share.status, true);
1198
1199 //negative tests
1200 SmbLocationItemDir directoryDoesNotExist;
1201 QCOMPARE(directoryDoesNotExist.mkdir("relativeDir"), false);
1202 QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist"), false);
1203 QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist/invalid_share"), false);
1204
1205 //positive tests
1206
1207 //create relative directory
1208 QString relativeName("relativeDir");
1209 SmbSharedPathAccess item = share.createPathForItem(relativeName);
1210 SmbLocationItemDir testRelative(share.url);
1211 SmbItemInfo smbDirBeforeCreation(item.smbUrl);
1212 //make sure directory does not exist
1213 QCOMPARE(smbDirBeforeCreation.exists(), false);
1214 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1215 //create directory using Samba
1216 QCOMPARE(testRelative.mkdir(relativeName), true);
1217 //make sure it exists now
1218 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1219 SmbItemInfo smbDirAfterCreation(item.smbUrl);
1220 QCOMPARE(smbDirAfterCreation.exists(), true);
1221
1222 //directory already exists, should return true
1223 QCOMPARE(testRelative.mkdir(relativeName), true);
1224
1225 //mkdir using absolute path
1226 item = share.createPathForItem("using_absolute_path");
1227 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1228 SmbLocationItemDir testAbsoluteDir;
1229 QCOMPARE(testAbsoluteDir.mkdir(item.smbUrl), true);
1230 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1231}
1232
1233
1234
1235void TestQSambaSuite::unit_QDir_mkpath()
1236{
1237 ShareCreationStatus share(createTempShare("unit_QDir_mkpath"));
1238 if (share.tempDir)
1239 {
1240 share.tempDir->setAutoRemove(true);
1241 }
1242 QCOMPARE(share.status, true);
1243
1244 //create multiple paths
1245 QStringList paths("path1");
1246 paths.append("path2");
1247 paths.append("path3");
1248 //item will have smbUrl=smb://localhost/shareName/path1/path2/path3 and diskPathname=/tmp/tmpdir/path1/path2/path3
1249 //using absolute path
1250 SmbSharedPathAccess item = share.createPathForItems(paths);
1251 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1252 SmbLocationItemDir testAbsoluteDir;
1253 QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
1254 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1255 //test when it already exists
1256 QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
1257
1258 //relative paths
1259 paths.clear();
1260 paths.append("relative1");
1261 paths.append("relative2");
1262 item = share.createPathForItems(paths);
1263 SmbLocationItemDir relativeDir(share.url);
1264 QString multiplePaths = paths.join(QDir::separator());
1265 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1266 QCOMPARE(relativeDir.mkpath(multiplePaths), true);
1267 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1268}
1269
1270
1271
1272void TestQSambaSuite::unit_QDir_rmdir()
1273{
1274 ShareCreationStatus share(createTempShare("unit_QDir_rmdir"));
1275 if (share.tempDir)
1276 {
1277 share.tempDir->setAutoRemove(true);
1278 }
1279 QCOMPARE(share.status, true);
1280
1281 //negative tests
1282 SmbLocationItemDir directoryEmptyName;
1283 QCOMPARE(directoryEmptyName.rmdir("none"), false);
1284 QString dirName("dirName");
1285 SmbSharedPathAccess item = share.createPathForItem(dirName);
1286 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1287 SmbLocationItemDir directoryDoesNotExist(share.url);
1288 QCOMPARE(directoryDoesNotExist.rmdir(dirName), false);
1289
1290 //create a directory
1291 SmbLocationItemDir directory(share.url);
1292 //create using relative
1293 QCOMPARE(directory.mkdir(dirName), true);
1294 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1295 //remove the relative directory
1296 QCOMPARE(directory.rmdir(dirName), true);
1297 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1298 //create it again and now remove using absolute url
1299 QCOMPARE(directory.mkdir(dirName), true);
1300 QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1301 SmbLocationItemDir emptyObject;
1302 QCOMPARE(emptyObject.rmdir(item.smbUrl), true);
1303 QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1304}
1305
1306
1307void TestQSambaSuite::unit_QDirIterator_path()
1308{
1309 ShareCreationStatus share(createTempShare("unit_QDirIterator_path"));
1310 if (share.tempDir)
1311 {
1312 share.tempDir->setAutoRemove(true);
1313 }
1314 QCOMPARE(share.status, true);
1315 QStringList paths = QStringList() << "path1" << "anotherPath" << "testdir" << "passThru" << "haha";
1316 QStringList files = QStringList() << "text.txt" << "hiper.html" << "document.odf" << "spread.odx" << "tx.list";
1317
1318 QStringList curPath;
1319 for (int counter=0; counter < paths.count() && counter < files.count(); ++counter)
1320 {
1321 curPath.append(paths.at(counter));
1322 SmbSharedPathAccess item = share.createPathForItems(curPath);
1323 QCOMPARE(QDir().mkpath(item.diskPathname), true);
1324 QString fileFullPath = item.diskPathname + QDir::separator() + files.at(counter);
1325 QFile file(fileFullPath);
1326 QCOMPARE(file.open(QFile::WriteOnly), true);
1327 file.close();
1328 }
1329
1330 QDir::Filters dirFilter = QDir::NoDotAndDotDot;
1331 QDir::Filters moreFilter[] = { QDir::AllEntries, QDir::Hidden, QDir::System };
1332
1333 for (uint counter=0; counter < sizeof(moreFilter)/sizeof(moreFilter[0]); ++counter)
1334 {
1335 dirFilter |= moreFilter[counter];
1336 QDirIterator dirIterator(share.sharedDirPath, dirFilter, QDirIterator::Subdirectories);
1337 SmbLocationDirIterator smbIterator(share.url, dirFilter, QDirIterator::Subdirectories);
1338 QStringList listDir;
1339 QStringList listSmb;
1340 qDebug() << "\n=================";
1341 while (dirIterator.hasNext() && smbIterator.hasNext())
1342 {
1343 qDebug() << dirIterator.next() << smbIterator.next();
1344 listDir.append(dirIterator.fileName());
1345 listSmb.append(smbIterator.fileName());
1346 }
1347 QCOMPARE(listDir, listSmb);
1348 }
1349}
1350
1351
1352void TestQSambaSuite::positive_statvfs()
1353{
1354 ShareCreationStatus share(createTempShare("positive_statvfs"));
1355 if (share.tempDir)
1356 {
1357 share.tempDir->setAutoRemove(true);
1358 }
1359 QCOMPARE(share.status, true);
1360
1361 struct statvfs diskVfs;
1362 struct statvfs smbVfs;
1363 ::memset(&diskVfs, 0, sizeof(struct statvfs));
1364 ::memset(&smbVfs, 0, sizeof(struct statvfs));
1365
1366 //using a file that exists
1367 SmbUtil smb;
1368 QCOMPARE((int)smb.getStatvfsInfo(share.fileContent.smbUrl, &smbVfs), 0);
1369 QCOMPARE(::statvfs(share.fileContent.diskPathname.toLocal8Bit().constData(), &diskVfs), 0);
1370 QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
1371 QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
1372 QCOMPARE(smbVfs.f_files, diskVfs.f_files);
1373 QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
1374 QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
1375
1376 //using a directory
1377 ::memset(&diskVfs, 0, sizeof(struct statvfs));
1378 ::memset(&smbVfs, 0, sizeof(struct statvfs));
1379 QCOMPARE((int)smb.getStatvfsInfo(share.url, &smbVfs), 0);
1380 QCOMPARE(::statvfs(share.sharedDirPath.toLocal8Bit().constData(), &diskVfs), 0);
1381 QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
1382 QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
1383 QCOMPARE(smbVfs.f_files, diskVfs.f_files);
1384 QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
1385 QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
1386}
7291387
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:44:54 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:44:54 +0000
@@ -90,6 +90,29 @@
90 void negative_emptyItemInfo();90 void negative_emptyItemInfo();
91 void negative_dirIterator();91 void negative_dirIterator();
9292
93private Q_SLOTS: //unit test for SmbLocationItemFile class
94 void unit_QFile_rename();
95 void unit_QFile_remove();
96 void unit_QFile_open();
97 void unit_QFile_read();
98 void unit_QFile_write();
99 void unit_QFile_atEnd();
100 void unit_QFile_size();
101 void unit_QFile_isOpen();
102 void unit_QFile_setPermissions();
103 void unit_QFile_permissions();
104
105private Q_SLOTS: //unit test for SmbLocationItemDir class
106 void unit_QDir_exists();
107 void unit_QDir_mkdir();
108 void unit_QDir_mkpath();
109 void unit_QDir_rmdir();
110
111private Q_SLOTS: //unit test for SmbLocationItemDirIterator class
112 void unit_QDirIterator_path();
113
114private Q_SLOTS:
115 void positive_statvfs();
93116
94protected: 117protected:
95 QString createTempFile(const QString& path,118 QString createTempFile(const QString& path,

Subscribers

People subscribed via source and target branches