static void processattributes(void) { int i,j; /* process global attributes*/ for(i=0;i<listlength(gattdefs);i++) { Symbol* asym = (Symbol*)listget(gattdefs,i); /* If the attribute has a zero length, then default it */ if(asym->data == NULL || asym->data->length == 0) { asym->data = builddatalist(1); emptystringconst(asym->lineno,&asym->data->data[asym->data->length]); /* force type to be NC_CHAR */ asym->typ.basetype = primsymbols[NC_CHAR]; } if(asym->typ.basetype == NULL) inferattributetype(asym); /* fill in the typecode*/ asym->typ.typecode = asym->typ.basetype->typ.typecode; } /* process per variable attributes*/ for(i=0;i<listlength(attdefs);i++) { Symbol* asym = (Symbol*)listget(attdefs,i); /* If the attribute has a zero length, then default it */ if(asym->data == NULL || asym->data->length == 0) { asym->data = builddatalist(1); emptystringconst(asym->lineno,&asym->data->data[asym->data->length]); /* force type to be NC_CHAR */ asym->typ.basetype = primsymbols[NC_CHAR]; } /* If no basetype is specified, then try to infer it; the exception if _Fillvalue, whose type is that of the containing variable. */ if(strcmp(asym->name,specialname(_FILLVALUE_FLAG)) == 0) { /* This is _Fillvalue */ asym->typ.basetype = asym->att.var->typ.basetype; /* its basetype is same as its var*/ /* put the datalist into the specials structure */ if(asym->data == NULL) { /* Generate a default fill value */ asym->data = getfiller(asym->typ.basetype); } asym->att.var->var.special._Fillvalue = asym->data; } else if(asym->typ.basetype == NULL) { inferattributetype(asym); } /* fill in the typecode*/ asym->typ.typecode = asym->typ.basetype->typ.typecode; } /* collect per-variable attributes per variable*/ for(i=0;i<listlength(vardefs);i++) { Symbol* vsym = (Symbol*)listget(vardefs,i); List* list = listnew(); for(j=0;j<listlength(attdefs);j++) { Symbol* asym = (Symbol*)listget(attdefs,j); ASSERT(asym->att.var != NULL); if(asym->att.var != vsym) continue; listpush(list,(void*)asym); } vsym->var.attributes = list; } }
/* We should not create an actual attribute for any of the special attributes. */ static void makespecial(int tag, Symbol* vsym, nc_type typ, Datalist* dlist) { Symbol* attr = install(specialname(tag)); attr->objectclass = NC_ATT; attr->data = dlist; if(vsym) { Symbol* grp = vsym->container; if(grp) listpush(grp->subnodes,(void*)attr); attr->container = grp; } attr->att.var = vsym; attr->typ.basetype = primsymbols[typ==NC_STRING?NC_CHAR:typ]; listpush(attdefs,(void*)attr); }
static void processattributes(void) { int i,j; /* process global attributes*/ for(i=0;i<listlength(gattdefs);i++) { Symbol* asym = (Symbol*)listget(gattdefs,i); if(asym->typ.basetype == NULL) inferattributetype(asym); /* fill in the typecode*/ asym->typ.typecode = asym->typ.basetype->typ.typecode; if(asym->data != NULL && asym->data->length == 0) { NCConstant* empty = NULL; /* If the attribute has a zero length, then default it; note that it must be of type NC_CHAR */ if(asym->typ.typecode != NC_CHAR) semerror(asym->lineno,"Empty datalist can only be assigned to attributes of type char",fullname(asym)); empty = emptystringconst(asym->lineno); dlappend(asym->data,empty); } validateNIL(asym); } /* process per variable attributes*/ for(i=0;i<listlength(attdefs);i++) { Symbol* asym = (Symbol*)listget(attdefs,i); /* If no basetype is specified, then try to infer it; the exception is _Fillvalue, whose type is that of the containing variable. */ if(strcmp(asym->name,specialname(_FILLVALUE_FLAG)) == 0) { /* This is _Fillvalue */ asym->typ.basetype = asym->att.var->typ.basetype; /* its basetype is same as its var*/ /* put the datalist into the specials structure */ if(asym->data == NULL) { /* Generate a default fill value */ asym->data = getfiller(asym->typ.basetype); } if(asym->att.var->var.special->_Fillvalue != NULL) reclaimdatalist(asym->att.var->var.special->_Fillvalue); asym->att.var->var.special->_Fillvalue = clonedatalist(asym->data); } else if(asym->typ.basetype == NULL) { inferattributetype(asym); } /* fill in the typecode*/ asym->typ.typecode = asym->typ.basetype->typ.typecode; if(asym->data->length == 0) { NCConstant* empty = NULL; /* If the attribute has a zero length, and is char type, then default it */ if(asym->typ.typecode != NC_CHAR) semerror(asym->lineno,"Empty datalist can only be assigned to attributes of type char",fullname(asym)); empty = emptystringconst(asym->lineno); dlappend(asym->data,empty); } validateNIL(asym); } /* collect per-variable attributes per variable*/ for(i=0;i<listlength(vardefs);i++) { Symbol* vsym = (Symbol*)listget(vardefs,i); List* list = listnew(); for(j=0;j<listlength(attdefs);j++) { Symbol* asym = (Symbol*)listget(attdefs,j); if(asym->att.var == NULL) continue; /* ignore globals for now */ if(asym->att.var != vsym) continue; listpush(list,(void*)asym); } vsym->var.attributes = list; } }
A2(PUBLIC, OSErr, ROMlib_serialopen, ParmBlkPtr, pbp, /* INTERNAL */ DCtlPtr, dcp) { OSErr err; auto DCtlPtr otherp; /* auto due to old compiler bug */ hiddenh h; #if defined (LINUX) || defined (NEXTSTEP) const char *devname, *tempname; LONGINT fd, ourpid, theirpid, newfd, oumask; #endif err = noErr; if (!(dcp->dCtlFlags & CWC(OPENBIT))) { h = (hiddenh) NewHandle(sizeof(hidden)); dcp->dCtlStorage = (Handle) RM(h); otherp = otherdctl(pbp); if (otherp && (otherp->dCtlFlags & CWC(OPENBIT))) { *STARH(h) = *STARH((hiddenh) (long) MR(otherp->dCtlStorage)); dcp->dCtlFlags |= CWC(OPENBIT); } else { #if defined (LINUX) || defined (NEXTSTEP) err = permErr; if ((devname = specialname(pbp, &lockname, &tempname))) { oumask = umask(0); if (!tempname) err = noErr; else if ((fd = Uopen(tempname, O_BINARY|O_CREAT|O_WRONLY, 0666L)) >= 0) { ourpid = getpid(); if (write(fd, &ourpid, sizeof(ourpid)) == sizeof(ourpid)) { if (Ulink(tempname, lockname) == 0) err = noErr; else { if ((newfd = Uopen(lockname, O_BINARY|O_RDWR, 0)) >= 0) { if (read(newfd, &theirpid, sizeof(theirpid)) == sizeof(theirpid)) if ((kill(theirpid, 0) != 0) && errno == ESRCH) { err = noErr; Uunlink(lockname); Ulink(tempname, lockname); } close(newfd); } } Uunlink(tempname); } close(fd); } umask(oumask); } #endif if (err == noErr) { #if defined (LINUX) || defined (NEXTSTEP) HxX(h, fd) = ROMlib_priv_open(devname, O_BINARY|O_RDWR); if (HxX(h, fd) < 0) err = HxX(h, fd); /* error return piggybacked */ else { #if defined(TERMIO) err = ioctl(HxX(h, fd), TCGETA, &HxX(h, state)) < 0 ? ROMlib_maperrno() : noErr; #else if (ioctl(HxX(h, fd), TIOCGETP, &HxX(h, sgttyb)) < 0 || ioctl(HxX(h, fd), TIOCGETC, &HxX(h, tchars)) < 0 || ioctl(HxX(h, fd), TIOCLGET, &HxX(h, lclmode)) < 0) err = ROMlib_maperrno(); #endif #else HxX(h, fd) = (CW(pbp->cntrlParam.ioCRefNum) == AINREFNUM || CW(pbp->cntrlParam.ioCRefNum) == AOUTREFNUM) ? 0 : 1; #endif dcp->dCtlFlags |= CWC(OPENBIT); SerReset(CW(pbp->cntrlParam.ioCRefNum), (CW(pbp->cntrlParam.ioCRefNum) == AINREFNUM || CW(pbp->cntrlParam.ioCRefNum) == AOUTREFNUM) ? CW(SPPortA) : CW(SPPortB)); #if defined (LINUX) || defined (NEXTSTEP) } #endif } } } #if defined(SERIALDEBUG) warning_trace_info("serial open returning %d", (LONGINT) err); #endif DOCOMPLETION(pbp, err); }
void KRenameTest::testBatchRenamer() { writeTestHeader( "BatchRenamer" ); // Testing the basic KRename tokens QString filename( " Test File name " ); QString directory1( "krename" ); QString directory2( "home" ); RUN_TOKEN_TEST( "$ Test", "$", filename, filename ); RUN_TOKEN_TEST( "& Test", "&", filename, filename.toUpper() ); RUN_TOKEN_TEST( "% Test", "%", filename, filename.toLower() ); RUN_TOKEN_TEST( "* Test", "*", filename, " Test File Name " ); RUN_TOKEN_TEST( "# Test", "#", filename, QString::number( 0 ) ); RUN_TOKEN_TEST( "## Test", "##", filename, QString().sprintf("%02i", 0 ) ); RUN_TOKEN_TEST( "### Test", "###", filename, QString().sprintf("%03i", 0 ) ); RUN_TOKEN_TEST( "#### Test", "####", filename, QString().sprintf("%04i", 0 ) ); RUN_TOKEN_TEST( "##### Test", "#####", filename, QString().sprintf("%05i", 0 ) ); RUN_TOKEN_TEST( "#{100;2} Test", "#{100;2}", filename, QString::number( 100 ) ); RUN_TOKEN_TEST( "####{100;2} Test", "####{100;2}", filename, QString().sprintf("%04i", 100 ) ); RUN_TOKEN_TEST( "####{2;2}## Test", "####{2;2}##", filename, QString().sprintf("%04i", 2 ) + QString().sprintf("%02i", 0 )); RUN_TOKEN_TEST( "[1] Test", "[1]", filename, QString( filename[0] ) ); RUN_TOKEN_TEST( "[2] Test", "[2]", filename, QString( filename[1] ) ); RUN_TOKEN_TEST( "[3] Test", "[3]", filename, QString( filename[2] ) ); RUN_TOKEN_TEST( "[&4] Test", "[&4]", filename, QString( filename[3].toUpper()) ); RUN_TOKEN_TEST( "[$4] Test", "[$4]", filename, QString( filename[3] ) ); RUN_TOKEN_TEST( "[%4] Test", "[%4]", filename, QString( filename[3].toLower()) ); RUN_TOKEN_TEST( "[*4] Test", "[*4]", filename, QString( filename[3].toUpper()) ); RUN_TOKEN_TEST( "[4-] Test", "[4-]", filename, filename.right( filename.length() - 3 ) ); RUN_TOKEN_TEST( "[&4-] Test", "[&4-]", filename, filename.right( filename.length() - 3 ).toUpper() ); RUN_TOKEN_TEST( "[$4-] Test", "[$4-]", filename, filename.right( filename.length() - 3 ) ); RUN_TOKEN_TEST( "[%4-] Test", "[%4-]", filename, filename.right( filename.length() - 3 ).toLower() ); RUN_TOKEN_TEST( "[*4-] Test", "[*4-]", filename, "St File Name " ); RUN_TOKEN_TEST( "[4-] Test", "[4-]", filename, filename.right( filename.length() - 3 ) ); RUN_TOKEN_TEST( "[&4-[length]] Test", "[&4-[length]]", filename, filename.right( filename.length() - 3 ).toUpper() ); RUN_TOKEN_TEST( "[$4-[length]] Test", "[$4-[length]]", filename, filename.right( filename.length() - 3 ) ); RUN_TOKEN_TEST( "[%4-[length]] Test", "[%4-[length]]", filename, filename.right( filename.length() - 3 ).toLower() ); RUN_TOKEN_TEST( "[*4-[length]] Test", "[*4-[length]]", filename, "St File Name " ); RUN_TOKEN_TEST( "[trimmed;[4-]] Test", "[trimmed;[4-]]", filename, filename.right( filename.length() - 3 ).trimmed() ); RUN_TOKEN_TEST( "[trimmed] Test", "[trimmed]", filename, filename.trimmed() ); RUN_TOKEN_TEST( "[length] Test", "[length]", filename, QString::number( filename.length() ) ); RUN_TOKEN_TEST( "[length-0] Test", "[length-0]", filename, QString::number( filename.length() ) ); RUN_TOKEN_TEST( "[length-1] Test", "[length-1]", filename, QString::number( filename.length() - 1 ) ); RUN_TOKEN_TEST( "[length-2] Test", "[length-2]", filename, QString::number( filename.length() - 2 ) ); RUN_TOKEN_TEST( "[#length] Test", "[#length]", filename, QString::number( filename.length() ) ); RUN_TOKEN_TEST( "[#length-0] Test", "[#length-0]", filename, QString::number( filename.length() ) ); RUN_TOKEN_TEST( "[#length-1] Test", "[#length-1]", filename, QString::number( filename.length() - 1 ) ); RUN_TOKEN_TEST( "[#length-2] Test", "[#length-2]", filename, QString::number( filename.length() - 2 ) ); RUN_TOKEN_TEST( "[####length] Test", "[####length]", filename, QString().sprintf("%04i", filename.length() ) ); RUN_TOKEN_TEST( "[####length-0] Test", "[####length-0]", filename, QString().sprintf("%04i", filename.length() ) ); RUN_TOKEN_TEST( "[####length-1] Test", "[####length-1]", filename, QString().sprintf("%04i", filename.length() - 1) ); RUN_TOKEN_TEST( "[####length-2] Test", "[####length-2]", filename, QString().sprintf("%04i", filename.length() - 2) ); RUN_TOKEN_TEST( "[6-9] Test", "[6-9]", filename, filename.mid( 5, 4 ) ); RUN_TOKEN_TEST( "[&6-9] Test", "[&6-9]", filename, filename.mid( 5, 4 ).toUpper() ); RUN_TOKEN_TEST( "[$6-9] Test", "[$6-9]", filename, filename.mid( 5, 4 ) ); RUN_TOKEN_TEST( "[%6-9] Test", "[%6-9]", filename, filename.mid( 5, 4 ).toLower() ); RUN_TOKEN_TEST( "[*6-9] Test", "[*6-9]", filename, filename.mid( 5, 4 ) ); RUN_TOKEN_TEST( "[trimmed;[6-9]] Test", "[trimmed;[6-9]]", filename, filename.mid( 5, 4 ).trimmed() ); RUN_TOKEN_TEST( "[6;4] Test", "[6;4]", filename, filename.mid( 5, 4 ) ); RUN_TOKEN_TEST( "[&6;4] Test", "[&6;4]", filename, filename.mid( 5, 4 ).toUpper() ); RUN_TOKEN_TEST( "[$6;4] Test", "[$6;4]", filename, filename.mid( 5, 4 ) ); RUN_TOKEN_TEST( "[%6;4] Test", "[%6;4]", filename, filename.mid( 5, 4 ).toLower() ); RUN_TOKEN_TEST( "[*6;4] Test", "[*6;4]", filename, filename.mid( 5, 4 ) ); RUN_TOKEN_TEST( "[1;1{[length]}] Test", "[1;1{[length]}]", filename, "1" ); RUN_TOKEN_TEST( "[trimmed;[6;4]] Test", "[trimmed;[6;4]]", filename, filename.mid( 5, 4 ).trimmed() ); RUN_TOKEN_TEST( "[trimmed; Hallo ] Test", "[trimmed; Hallo ]", filename, "Hallo" ); RUN_TOKEN_TEST( "[dirname] Test", "[dirname]", filename, directory1 ); RUN_TOKEN_TEST( "[&dirname] Test", "[&dirname]", filename, directory1.toUpper() ); RUN_TOKEN_TEST( "[$dirname] Test", "[$dirname]", filename, directory1 ); RUN_TOKEN_TEST( "[%dirname] Test", "[%dirname]", filename, directory1.toLower() ); RUN_TOKEN_TEST( "[*dirname] Test", "[*dirname]", filename, "Krename" ); RUN_TOKEN_TEST( "[trimmed;[dirname]] Test", "[trimmed;[dirname]]", filename, directory1 ); RUN_TOKEN_TEST( "[dirname.] Test", "[dirname.]", filename, directory2 ); RUN_TOKEN_TEST( "[&dirname.] Test", "[&dirname.]", filename, directory2.toUpper() ); RUN_TOKEN_TEST( "[$dirname.] Test", "[$dirname.]", filename, directory2 ); RUN_TOKEN_TEST( "[%dirname.] Test", "[%dirname.]", filename, directory2.toLower() ); RUN_TOKEN_TEST( "[*dirname.] Test", "[*dirname.]", filename, "Home" ); RUN_TOKEN_TEST( "[trimmed;[dirname.]] Test", "[trimmed;[dirname.]]", filename, directory2 ); RUN_TOKEN_TEST( "[dirname..] Test", "[dirname..]", filename, "" ); RUN_TOKEN_TEST( "[&dirname..] Test", "[&dirname..]", filename, "" ); RUN_TOKEN_TEST( "[$dirname..] Test", "[$dirname..]", filename, "" ); RUN_TOKEN_TEST( "[%dirname..] Test", "[%dirname..]", filename, "" ); RUN_TOKEN_TEST( "[*dirname..] Test", "[*dirname..]", filename, "" ); // TODO: This test has strange effects that only occur if [dirname..] is QString::null //RUN_TOKEN_TEST( "[trimmed;[dirname..]] Test", "[trimmed;[dirname..]]", filename, filename.trimmed() ); RUN_TOKEN_TEST( "Complex Test1", "&[2-5]", filename, filename.toUpper() + "Test" ); RUN_TOKEN_TEST( "Complex Test2", "%[2-5]", filename, filename.toLower() + "Test" ); RUN_TOKEN_TEST( "Complex Test3", "$[2-5]", filename, filename + "Test" ); RUN_TOKEN_TEST( "Complex Test4", "*[2-5]", filename, " Test File Name Test" ); RUN_TOKEN_TEST( "Complex Test5", "[trimmed][2-5]", filename, filename.trimmed() + "Test" ); RUN_TOKEN_TEST( "Complex Test6", "[&2-5]\\&[length-2]\\&[1;1{Hallo}]", filename, "TEST&14&H" ); // Testing all special Characters in KRename RUN_TOKEN_TEST( "\\/ Test", "\\/", filename, "%2f" ); // this is displayed as a slash, // unix filenames are not allowed // to contain a slash RUN_TOKEN_TEST( "\\[ Test", "\\[", filename, "[" ); RUN_TOKEN_TEST( "\\] Test", "\\]", filename, "]" ); RUN_TOKEN_TEST( "\\$ Test", "\\$", filename, "$" ); RUN_TOKEN_TEST( "\\* Test", "\\*", filename, "*" ); RUN_TOKEN_TEST( "\\\\ Test", "\\\\", filename, "\\" ); RUN_TOKEN_TEST( "\\& Test", "\\&", filename, "&" ); RUN_TOKEN_TEST( "\\% Test", "\\%", filename, "%" ); RUN_TOKEN_TEST( "\\# Test", "\\#", filename, "#" ); // Testing filenames with special characters QString specialname("Test %1 File"); RUN_TOKEN_TEST( "File [ Test", "$", specialname.arg( "[" ), specialname.arg( "[" ) ); RUN_TOKEN_TEST( "File ] Test", "$", specialname.arg( "]" ), specialname.arg( "]" ) ); RUN_TOKEN_TEST( "File $ Test", "$", specialname.arg( "$" ), specialname.arg( "$" ) ); RUN_TOKEN_TEST( "File * Test", "$", specialname.arg( "*" ), specialname.arg( "*" ) ); RUN_TOKEN_TEST( "File \\ Test", "$", specialname.arg( "\\" ), specialname.arg( "\\" ) ); RUN_TOKEN_TEST( "File & Test", "$", specialname.arg( "&" ), specialname.arg( "&" ) ); RUN_TOKEN_TEST( "File % Test", "$", specialname.arg( "%" ), specialname.arg( "%" ) ); RUN_TOKEN_TEST( "File # Test", "$", specialname.arg( "#" ), specialname.arg( "#" ) ); // load all plugins now //PluginLoader::instance()->loadPlugins( false ); // file plugins are not required // Testing system functions RUN_TOKEN_TEST( "Date Test", "[date]", filename, QDateTime::currentDateTime().toString( "dd-MM-yyyy") ); RUN_TOKEN_TEST( "dd-MM-yyyy Date Test", "[date;dd-MM-yyyy]", filename, QDateTime::currentDateTime().toString( "dd-MM-yyyy") ); RUN_TOKEN_TEST( "dd:MM:yyyy Date Test", "[date;dd:MM:yyyy]", filename, QDateTime::currentDateTime().toString( "dd:MM:yyyy") ); RUN_TOKEN_TEST( "yy.mm.dd Date Test", "[date;yy.mm.dd]", filename, QDateTime::currentDateTime().toString( "yy.mm.dd") ); RUN_TOKEN_TEST( "d Date Test", "[date;d]", filename, QDateTime::currentDateTime().toString( "d") ); RUN_TOKEN_TEST( "dd Date Test", "[date;dd]", filename, QDateTime::currentDateTime().toString( "dd") ); RUN_TOKEN_TEST( "ddd Date Test", "[date;ddd]", filename, QDateTime::currentDateTime().toString( "ddd") ); RUN_TOKEN_TEST( "dddd Date Test", "[date;dddd]", filename, QDateTime::currentDateTime().toString( "dddd") ); RUN_TOKEN_TEST( "M Date Test", "[date;M]", filename, QDateTime::currentDateTime().toString( "M") ); RUN_TOKEN_TEST( "MM Date Test", "[date;MM]", filename, QDateTime::currentDateTime().toString( "MM") ); RUN_TOKEN_TEST( "MMM Date Test", "[date;MMM]", filename, QDateTime::currentDateTime().toString( "MMM") ); RUN_TOKEN_TEST( "MMMM Date Test", "[date;MMMM]", filename, QDateTime::currentDateTime().toString( "MMMM") ); RUN_TOKEN_TEST( "yy Date Test", "[date;yy]", filename, QDateTime::currentDateTime().toString( "yy") ); RUN_TOKEN_TEST( "yyyy Date Test", "[date;yyyy]", filename, QDateTime::currentDateTime().toString( "yyyy") ); RUN_TOKEN_TEST( "h Date Test", "[date;h]", filename, QDateTime::currentDateTime().toString( "h") ); RUN_TOKEN_TEST( "hh Date Test", "[date;hh]", filename, QDateTime::currentDateTime().toString( "hh") ); RUN_TOKEN_TEST( "m Date Test", "[date;m]", filename, QDateTime::currentDateTime().toString( "m") ); RUN_TOKEN_TEST( "mm Date Test", "[date;mm]", filename, QDateTime::currentDateTime().toString( "mm") ); RUN_TOKEN_TEST( "s Date Test", "[date;s]", filename, QDateTime::currentDateTime().toString( "s") ); RUN_TOKEN_TEST( "ss Date Test", "[date;ss]", filename, QDateTime::currentDateTime().toString( "ss") ); // Current computers are to slow to compare two milliseconds as the instruction is longer than // a millisecond. // // RUN_TOKEN_TEST( "z Date Test", "[date;z]", filename, QDateTime::currentDateTime().toString( "z") ); // RUN_TOKEN_TEST( "zzz Date Test", "[date;zzz]", filename, QDateTime::currentDateTime().toString( "zzz") ); RUN_TOKEN_TEST( "ap Date Test", "[date;ap]", filename, QDateTime::currentDateTime().toString( "ap") ); RUN_TOKEN_TEST( "AP Date Test", "[date;AP]", filename, QDateTime::currentDateTime().toString( "AP") ); RUN_TOKEN_TEST( "Day Test", "[day]", filename, QDateTime::currentDateTime().toString( "dd") ); RUN_TOKEN_TEST( "Month Test", "[month]", filename, QDateTime::currentDateTime().toString( "MM") ); RUN_TOKEN_TEST( "Year Test", "[year]", filename, QDateTime::currentDateTime().toString( "yyyy") ); RUN_TOKEN_TEST( "Hour Test", "[hour]", filename, QDateTime::currentDateTime().toString( "hh") ); RUN_TOKEN_TEST( "Minute Test", "[minute]", filename, QDateTime::currentDateTime().toString( "mm") ); RUN_TOKEN_TEST( "Second Test", "[second]", filename, QDateTime::currentDateTime().toString( "ss") ); RUN_TOKEN_TEST( "Time Test", "[time]", filename, QDateTime::currentDateTime().toString( "hh-mm-ss") ); // Testing numbering name, start, step, skip RUN_NUMBER_TESTS( "Numbers 0- Step 1", 0, 1, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 1- Step 1", 1, 1, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 2- Step 1", 2, 1, QList<int>() ); RUN_NUMBER_TESTS( "Numbers -2- Step 1", -2, 1, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 0- Step 2", 0, 2, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 1- Step 2", 1, 2, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 2- Step 2", 2, 2, QList<int>() ); RUN_NUMBER_TESTS( "Numbers -2- Step 2", -2, 2, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 0- Step 7", 0, 7, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 1- Step 7", 1, 7, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 2- Step 7", 2, 7, QList<int>() ); RUN_NUMBER_TESTS( "Numbers -2- Step 7", -2, 7, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 0- Step -3", 0, -3, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 1- Step -3", 1, -3, QList<int>() ); RUN_NUMBER_TESTS( "Numbers 2- Step -3", 2, -3, QList<int>() ); RUN_NUMBER_TESTS( "Numbers -2- Step -3", -2, -3, QList<int>() ); RUN_NUMBER_TESTS( "Skip 0- Step 1", 0, 1, QList<int>() << 1 << 2 << 3 << 4 << 89); RUN_NUMBER_TESTS( "Skip 1- Step 1", 1, 1, QList<int>() << 1 << 2 << 3 << 4 << 89); RUN_NUMBER_TESTS( "Skip 2- Step 1", 2, 1, QList<int>() << 1 << 2 << 3 << 4 << 89); RUN_NUMBER_TESTS( "Skip -2- Step 1", -2, 1, QList<int>() << 1 << 2 << 3 << 4 << 89); RUN_NUMBER_TESTS( "Skip 10- Step 79", 10, 79, QList<int>() << 1 << 2 << 3 << 4 << 89); RUN_NUMBER_TESTS( "Skip 10- Step -2", 10, -2, QList<int>() << 1 << 2 << 3 << 4 << 89); RUN_NUMBER_TESTS( "Skip 10- Step -1", 10, -1, QList<int>() << 1 << 2 << 3 << 4 << 89); // Test the find and replace feature of KRename RUN_REPLACE_TEST( "Replace: Spaces", "$", "Filename with spaces", "Filename_with_spaces", " ", "_", false ); RUN_REPLACE_TEST( "Replace: Nothing", "$", "Filename", "Filename", " ", "_", false ); RUN_REPLACE_TEST( "Replace: Word", "$", "Filename with spaces", "Filename HAS spaces", "with", "HAS", false ); RUN_REPLACE_TEST( "Replace: $", "$", "Filename with $ and spaces", "Filename with ! and spaces", "$", "!", false ); RUN_REPLACE_TEST( "Replace: &", "$", "Filename with & and spaces", "Filename with ! and spaces", "&", "!", false ); RUN_REPLACE_TEST( "Replace: %", "$", "Filename with % and spaces", "Filename with ! and spaces", "%", "!", false ); RUN_REPLACE_TEST( "Replace: *", "$", "Filename with * and spaces", "Filename with ! and spaces", "*", "!", false ); RUN_REPLACE_TEST( "Replace: [", "$", "Filename with [ and spaces", "Filename with ! and spaces", "[", "!", false ); RUN_REPLACE_TEST( "Replace: ]", "$", "Filename with ] and spaces", "Filename with ! and spaces", "]", "!", false ); RUN_REPLACE_TEST( "Replace: #", "$", "Filename with # and spaces", "Filename with ! and spaces", "#", "!", false ); RUN_REPLACE_TEST( "Replace: to $", "$", "Filename with spaces", "Filename $ spaces", "with", "$", false ); RUN_REPLACE_TEST( "Replace: to &", "$", "Filename with spaces", "Filename & spaces", "with", "&", false ); RUN_REPLACE_TEST( "Replace: to %", "$", "Filename with spaces", "Filename % spaces", "with", "%", false ); RUN_REPLACE_TEST( "Replace: to *", "$", "Filename with spaces", "Filename * spaces", "with", "*", false ); RUN_REPLACE_TEST( "Replace: to [", "$", "Filename with spaces", "Filename [ spaces", "with", "[", false ); RUN_REPLACE_TEST( "Replace: to ]", "$", "Filename with spaces", "Filename ] spaces", "with", "]", false ); RUN_REPLACE_TEST( "Replace: to #", "$", "Filename with spaces", "Filename # spaces", "with", "#", false ); RUN_REPLACE_TEST( "RegExp: ?", "$", "Filename", "AAAAAAAAA", "[a-zA-z]?", "A", true ); RUN_REPLACE_TEST( "RegExp: {1}", "$", "Filename", "AAAAAAAA", "[a-zA-z]{1}", "A", true ); RUN_REPLACE_TEST( "RegExp: +", "$", "Filename", "A", "[a-zA-z]+", "A", true ); RUN_REPLACE_TEST( "RegExp: \\d", "$", "Filename 123", "Filename NumberNumberNumber", "\\d", "Number", true ); RUN_REPLACE_TEST( "RegExp: \\d+", "$", "Filename 123", "Filename Number", "\\d+", "Number", true ); RUN_REPLACE_TEST( "RegExp: Match", "$", "Filename 123", "MATCHING", "[a-zA-z]* \\d{3}", "MATCHING", true ); // TODO: // TODO: Manual Change Test // Regression tests // Caused an infinite loop RUN_TOKEN_TEST( "[1-2 [4-] Test", "[1-2 [4-]", filename, " " + filename.right( filename.length() - 3 ) ); const char* regTemplate = "###{329;13"; RUN_TOKEN_TEST( regTemplate, regTemplate, filename, "329" ); RUN_TOKEN_TEST( "ABC {1", "ABC {1", filename, "ABC {1" ); // Brackets appeared as \[ in the final result QString regressionName = "1-07 Take Flight (Wings) [Pocketman]"; QString regressionExpect = "100-Take Flight (Wings) [Pocketman]"; RUN_TOKEN_TEST( "1##-[$6-] Test", "1##-[$6-]", regressionName, regressionExpect ); KRenameFile::List files; QStringList expected; QStringList expectedPaths; files << KRenameFile( KUrl("/home/foo/bar/subdir"), true, eSplitMode_FirstDot, 1 ) << KRenameFile( KUrl("/home/foo"), true, eSplitMode_FirstDot, 1 ) << KRenameFile( KUrl("/home/foo/bar"), true, eSplitMode_FirstDot, 1 ) << KRenameFile( KUrl("/home/foo/bar/baz"), true, eSplitMode_FirstDot, 1 ); expected << "SUBDIR" << "FOO" << "BAR" << "BAZ"; expectedPaths << "/home/foo/bar" << "/home" << "/home/FOO" << "/home/FOO/BAR"; RUN_KRENAME_MULTI_FILE_TEST( files, expected, expectedPaths, "&", "Testing a directory hirarchy" ); }