ewmscp  ..
Public Member Functions | List of all members
uglyNames Class Reference
Inheritance diagram for uglyNames:
[legend]
Collaboration diagram for uglyNames:
[legend]

Public Member Functions

 uglyNames ()
 
void execute (const std::vector< std::string > &remainingOptions) override
 
- Public Member Functions inherited from baseTest
 baseTest (const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
 
void ensuredWrite (int fd, const std::string &data)
 
void ensuredRead (int fd, std::string &data)
 
void Execute (const std::vector< std::string > &remainingOptions)
 

Additional Inherited Members

- Static Public Member Functions inherited from baseTest
static std::map< std::string, baseTest * > & getList ()
 
static void setUpOptions ()
 
static const std::string & getDescriptions ()
 
- Protected Attributes inherited from baseTest
std::string name
 
std::string description
 
std::list< std::pair< std::string, std::string > > parameters
 
std::list< std::pair< options::base &, std::string > > options
 
std::set< std::string > createdFiles
 
- Static Protected Attributes inherited from baseTest
static options::single< unsigned int > repeat
 
static options::single< bool > cleanup
 
static options::single< bool > urandom
 
static options::single< bool > einsZweiDrei
 
static options::single< std::string > contentFile
 
static options::single< size_t > size
 
static options::single< unsigned int > blocks
 
static options::single< std::string > content
 
static options::single< bool > truncate
 
static options::single< std::chrono::duration< double > > time
 
static options::single< unsigned long > syncus
 
static options::single< unsigned long > skewus
 
static std::string descriptions = "\npossible actions and their parameters:\n"
 

Detailed Description

Definition at line 737 of file fileOpsTests.cpp.

Constructor & Destructor Documentation

◆ uglyNames()

uglyNames::uglyNames ( )
inline

Definition at line 739 of file fileOpsTests.cpp.

739  : baseTest("uglyNames",
740  "write files with ugly names", {
741  {"dir", "directory to create the files in"
742  }
743  }) {};

Member Function Documentation

◆ execute()

void uglyNames::execute ( const std::vector< std::string > &  remainingOptions)
inlineoverridevirtual

Implements baseTest.

Definition at line 744 of file fileOpsTests.cpp.

744  {
745  auto dir = remainingOptions.at(0);
746  auto dirfd = throwcall::badval(open(dir.c_str(),O_PATH | O_DIRECTORY),-1,"can't open ",dir);
747  std::list<std::string> names{"name with spaces",
748  "name\nwith\nnewlines",
749  "name\rwith\rreturns",
750  "name\r\nwith\r\nCRLF",
751  "name_with_\033[91mred\033[0m_part",
752  "name_with_\xe2\x80\xadleft-to-right\xe2\x80\x8e_part",
753  "name_with_\xe2\x82\xac_euro",
754  "name_with_ɄɳɨȻʘΔε_unicode",
755  "name_with_🤔💩☢_emojis",
756  "name_with_䭫顙_more_unicode"
757  };
758  {
759  std::list<std::pair<std::string,unsigned char>> ControlChars{
760  {"SOH", 001}, {"STX", 002}, {"ETX", 003}, {"EOT", 004},
761  {"ENQ", 005}, {"ACK", 006},
762  {"BEL", 007},
763  {"BS", 010},
764  {"HT", 011},
765  {"LF", 012},
766  {"VT", 013},
767  {"FF", 014},
768  {"CR", 015},
769  {"SO", 016},
770  {"SI", 017},
771  {"DLE", 020},
772  {"DC1", 021},
773  {"DC2", 022},
774  {"DC3", 023},
775  {"DC4", 024},
776  {"NAK", 025},
777  {"SYN", 026},
778  {"ETB", 027},
779  {"CAN", 030},
780  {"EM", 031},
781 {"SUB", 032},
782 {"ESC", 033},
783 {"FS", 034},
784 {"GS", 035},
785 {"RS", 036},
786 {"US", 037},
787 {"DEL",0177}
788  };
789  for (const auto& cc: ControlChars) {
790  std::string ugly("name_with_");
791  ugly.push_back(cc.second);
792  ugly+="_char_";
793  ugly+=std::to_string(cc.second);
794  ugly+="_";
795  ugly+=cc.first;
796  names.push_back(ugly);
797  }
798  }
799  {
800  std::vector<std::pair<unsigned char, unsigned char>> ranges{{32,46},{58,63},{91,96},{123,126}};
801  for (const auto& range: ranges) {
802  for (unsigned char c=range.first; c<=range.second; c++) {
803  std::string ugly("name_with_");
804  ugly.push_back(c);
805  ugly+="_char_";
806  ugly+=std::to_string(c);
807  names.push_back(ugly);
808  }
809  }
810  }
811  for (unsigned char c=128; c!=0; c++) {
812  std::string ugly("name_with_");
813  ugly.push_back(c);
814  ugly+="_char_";
815  ugly+=std::to_string(c);
816  names.push_back(ugly);
817  }
818  {
819  auto nameMax = throwcall::badval(fpathconf(dirfd,_PC_NAME_MAX),-1,"can't get max name length");
820  auto ugly = std::to_string(nameMax);
821  ugly.resize(nameMax,'b');
822  names.push_back(ugly);
823  }
824 
825  for (const auto& ugly: names) {
826  std::string file(dir);
827  file+="/";
828  file+=ugly;
829  auto fd = openat(dirfd,ugly.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0744);
830  if (fd == -1 && errno == EINVAL) {
831  std::cerr << "illegal file name \" << ugly << \" tried: ";
832  for (auto c : ugly) {
833  std::cerr << std::hex << std::setw(2) << c;
834  }
835  std::cerr << std::dec << "\n";
836  continue;
837  } else {
838  throwcall::badval(fd,-1, "open ", file);
839  }
840  ensuredWrite(fd, ugly);
841  throwcall::good0(close(fd), "close ", file);
842  createdFiles.emplace(file);
843  }
844  };

References throwcall::badval(), baseTest::createdFiles, baseTest::ensuredWrite(), and throwcall::good0().

Here is the call graph for this function:

The documentation for this class was generated from the following file:
throwcall::badval
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
Definition: throwcall.h:54
baseTest::createdFiles
std::set< std::string > createdFiles
Definition: fileOpsTests.cpp:42
baseTest::baseTest
baseTest(const std::string &aName, const std::string &aDescription, const decltype(parameters)&aParameters, const decltype(options)&aOptions={})
Definition: fileOpsTests.cpp:68
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
baseTest::ensuredWrite
void ensuredWrite(int fd, const std::string &data)
Definition: fileOpsTests.cpp:106