Skip to content
Snippets Groups Projects
Commit df183505 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

filled VSN1 class description.

moved all VSN1::fileds to private to not allow any direct modifications.
implemented Tape::AULFile::VOL1::verify function.
added unitest for Tape::AULFile::VOL1
added some helper functions to deal with space padded char arrays in the
 tape headers (cmpString, toString, spaceStruct).
parent 36b87cfc
Branches
Tags
No related merge requests found
......@@ -68,7 +68,7 @@ add_subdirectory(Drive)
add_subdirectory(System)
add_subdirectory(Exception)
add_subdirectory(Utils)
add_subdirectory(File)
# .. and then tools, tests, and daemon
# add_subdirectory(tools)
# add_subdirectory(deamon)
......
add_library(File Structures.cc)
......@@ -21,8 +21,38 @@
************************************************************************/
#include "Structures.hh"
#include "../Exception/Exception.hh"
void Tape::AULFile::VOL1::fill(std::string vsn) {
setString(label, "VOL1");
setString(VSN, vsn);
}
\ No newline at end of file
setString(lblStandart,"3");
setString(ownerID, "CASTOR"); /* TODO: check do we need CASTOR's STAGERSUPERUSER */
}
void Tape::AULFile::VOL1::verify() {
if (cmpString(label,"VOL1"))
throw Tape::Exceptions::Errnum(std::string("Failed check for the VOL1: ")+
Tape::AULFile::toString(label));
if (!cmpString(VSN,""))
throw Tape::Exceptions::Errnum(std::string("Failed check for the VSN: ") +
Tape::AULFile::toString(VSN));
if (cmpString(lblStandart,"3"))
throw Tape::Exceptions::Errnum(
std::string("Failed check for the label standart: ") +
Tape::AULFile::toString(lblStandart));
if (cmpString(ownerID,"CASTOR"))
throw Tape::Exceptions::Errnum(
std::string("Failed check for the ownerID: ") +
Tape::AULFile::toString(ownerID));
/* now we check all other fields which must be spaces */
if (cmpString(accessibility,""))
throw Tape::Exceptions::Errnum("accessibility is not empty");
if (cmpString(reserved1,""))
throw Tape::Exceptions::Errnum("reserved1 is not empty");
if (cmpString(implID,""))
throw Tape::Exceptions::Errnum("implID is not empty");
if (cmpString(reserved2,""))
throw Tape::Exceptions::Errnum("reserved2 is not empty");
}
......@@ -22,19 +22,54 @@
#pragma once
#include <string>
#include "string.h"
namespace Tape {
namespace AULFile {
/**
* Helper template to fill with space a structure.
* @param s pointer the struct/class.
*/
template <typename C>
void spaceStruct(C * s) {
memset (s, 0x20, sizeof(C));
}
template <size_t n>
/**
* Templated helper function to get std::string from the char array
* padded with spaces.
* @param t array pointer to the char array.
* @return std::string for the char array
*/
std::string toString(char(& t)[n]) {
std::string r;
r.assign(t,n);
return r;
}
class VOL1 {
public:
char label[4];
char VSN[6];
/* TODO: finish */
VOL1() { spaceStruct(this);}
private:
char label[4]; // The characters VOL1.
char VSN[6]; // The Volume Serial Number.
char accessibility[1];// A space indicates that the volume is authorized.
char reserved1[13]; // Reserved.
char implID[13]; // The Implementation Identifier - spaces.
char ownerID[14]; // CASTOR or stagesuperuser name padded with spaces.
char reserved2[28]; // Reserved */
char lblStandart[1]; // The label standart level - ASCII 3 for the CASTOR
public:
/**
* Fills up all fields of the VOL1 structure with proper values and data provided.
* @param VSN the tape serial number
*/
void fill(std::string _VSN);
/**
* @return VSN the tape serial number
*/
inline std::string getVSN() {
return toString(VSN);
}
/**
* Throws an exception if the structure does not match expectations.
*/
......@@ -48,8 +83,19 @@ namespace Tape {
void setString(char(& t)[n], const std::string & s) {
size_t written = s.copy(t, n);
if (written < n) {
memset(t[written],' ', n - written);
memset(&t[written],' ', n - written);
}
}
template <size_t n>
/**
* Templated helper function to compare a string with space padded string.
*
* @return Returns an integer equal to zero if strings match
*/
int cmpString(char(& t)[n], const std::string & s) {
char forCmp[n];
setString(forCmp,s);
return strncmp(forCmp,t,n);
}
}
}
\ No newline at end of file
}
......@@ -4,12 +4,13 @@ add_executable(unitTest unitTest.cc
../Utils/RegexTest.cc
../Drive/DriveTest.cc
../Exception/ExceptionTest.cc
../File/StructuresTest.cc
)
set_property(SOURCE ../SCSI/StructuresTest.cc
PROPERTY COMPILE_FLAGS -fno-strict-aliasing
)
target_link_libraries(unitTest TapeDrive Exception SCSI System Utils ${GTEST_LIBRARY} gmock pthread)
target_link_libraries(unitTest TapeDrive Exception SCSI System Utils File ${GTEST_LIBRARY} gmock pthread)
install(TARGETS unitTest
RUNTIME DESTINATION bin)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment