|
|
|
@ -119,6 +119,168 @@ func TestLoadFile_happyCase(t *testing.T) {
|
|
|
|
|
os.Remove(temporaryDataFileName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLoadFile_happyCase_date(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
//Given
|
|
|
|
|
dataArray := make([]string, 0)
|
|
|
|
|
dataArray = append(dataArray, "{ Sample multi-line comment")
|
|
|
|
|
dataArray = append(dataArray, " ( with quotes) Check: Logging > \"Contest Logging\"")
|
|
|
|
|
dataArray = append(dataArray, " - Data item1")
|
|
|
|
|
dataArray = append(dataArray, " - Data item2")
|
|
|
|
|
dataArray = append(dataArray, " }")
|
|
|
|
|
dataArray = append(dataArray, "{ one liner comment }")
|
|
|
|
|
dataArray = append(dataArray, " { offset one liner comment }")
|
|
|
|
|
dataArray = append(dataArray, " ")
|
|
|
|
|
dataArray = append(dataArray, "# Header")
|
|
|
|
|
dataArray = append(dataArray, "myCall on4kjm/p")
|
|
|
|
|
dataArray = append(dataArray, "operator on4kjm")
|
|
|
|
|
dataArray = append(dataArray, "nickname Portable")
|
|
|
|
|
dataArray = append(dataArray, " ")
|
|
|
|
|
dataArray = append(dataArray, " #Log")
|
|
|
|
|
dataArray = append(dataArray, "20/5/23")
|
|
|
|
|
dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5")
|
|
|
|
|
dataArray = append(dataArray, "on6zq")
|
|
|
|
|
dataArray = append(dataArray, "0954 on4do")
|
|
|
|
|
|
|
|
|
|
temporaryDataFileName := createTestFile(dataArray)
|
|
|
|
|
|
|
|
|
|
//When
|
|
|
|
|
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
|
|
|
|
|
|
|
|
|
|
//Then
|
|
|
|
|
if !isLoadedOK {
|
|
|
|
|
t.Error("Test file could not be correctly processed")
|
|
|
|
|
}
|
|
|
|
|
if len(loadedLogFile) == 0 {
|
|
|
|
|
t.Error("No data loaded")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedValue := "ON4KJM/P"
|
|
|
|
|
if loadedLogFile[0].MyCall != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected MyCall value: %s (expecting %s)", loadedLogFile[0].MyCall, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "ON4KJM"
|
|
|
|
|
if loadedLogFile[0].Operator != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Operator value: %s (expecting %s)", loadedLogFile[0].Operator, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "Portable"
|
|
|
|
|
if loadedLogFile[0].Nickname != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected eQsl Nickname value: %s (expecting %s)", loadedLogFile[0].Nickname, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "IK5ZVE/5"
|
|
|
|
|
if loadedLogFile[0].Call != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Call[0] value: %s (expecting %s)", loadedLogFile[0].Call, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "0950"
|
|
|
|
|
if loadedLogFile[0].Time != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Time[0] value: %s (expecting %s)", loadedLogFile[0].Time, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "2020-05-23"
|
|
|
|
|
if loadedLogFile[0].Date != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Date[0] value: %s (expecting %s)", loadedLogFile[0].Date, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "ON6ZQ"
|
|
|
|
|
if loadedLogFile[1].Call != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Call[1] value: %s (expecting %s)", loadedLogFile[1].Call, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "0952"
|
|
|
|
|
if loadedLogFile[1].Time != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Time[1] value: %s (expecting %s)", loadedLogFile[1].Time, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "ON4DO"
|
|
|
|
|
if loadedLogFile[2].Call != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Call[2] value: %s (expecting %s)", loadedLogFile[2].Call, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "0954"
|
|
|
|
|
if loadedLogFile[2].Time != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Time[2] value: %s (expecting %s)", loadedLogFile[2].Time, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
//Clean Up
|
|
|
|
|
os.Remove(temporaryDataFileName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLoadFile_bad_date(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
//Given
|
|
|
|
|
dataArray := make([]string, 0)
|
|
|
|
|
dataArray = append(dataArray, "{ Sample multi-line comment")
|
|
|
|
|
dataArray = append(dataArray, " ( with quotes) Check: Logging > \"Contest Logging\"")
|
|
|
|
|
dataArray = append(dataArray, " - Data item1")
|
|
|
|
|
dataArray = append(dataArray, " - Data item2")
|
|
|
|
|
dataArray = append(dataArray, " }")
|
|
|
|
|
dataArray = append(dataArray, "{ one liner comment }")
|
|
|
|
|
dataArray = append(dataArray, " { offset one liner comment }")
|
|
|
|
|
dataArray = append(dataArray, " ")
|
|
|
|
|
dataArray = append(dataArray, "# Header")
|
|
|
|
|
dataArray = append(dataArray, "myCall on4kjm/p")
|
|
|
|
|
dataArray = append(dataArray, "operator on4kjm")
|
|
|
|
|
dataArray = append(dataArray, "nickname Portable")
|
|
|
|
|
dataArray = append(dataArray, "date 2020-5-18")
|
|
|
|
|
dataArray = append(dataArray, " ")
|
|
|
|
|
dataArray = append(dataArray, " #Log")
|
|
|
|
|
dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5")
|
|
|
|
|
dataArray = append(dataArray, "20/5/233")
|
|
|
|
|
dataArray = append(dataArray, "on6zq")
|
|
|
|
|
dataArray = append(dataArray, "0954 on4do")
|
|
|
|
|
|
|
|
|
|
temporaryDataFileName := createTestFile(dataArray)
|
|
|
|
|
|
|
|
|
|
//When
|
|
|
|
|
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
|
|
|
|
|
|
|
|
|
|
//Then
|
|
|
|
|
if isLoadedOK {
|
|
|
|
|
t.Error("Test file processing should return with an error")
|
|
|
|
|
}
|
|
|
|
|
if len(loadedLogFile) == 0 {
|
|
|
|
|
t.Error("No data loaded")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedValue := "ON4KJM/P"
|
|
|
|
|
if loadedLogFile[0].MyCall != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected MyCall value: %s (expecting %s)", loadedLogFile[0].MyCall, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "ON4KJM"
|
|
|
|
|
if loadedLogFile[0].Operator != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Operator value: %s (expecting %s)", loadedLogFile[0].Operator, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "Portable"
|
|
|
|
|
if loadedLogFile[0].Nickname != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected eQsl Nickname value: %s (expecting %s)", loadedLogFile[0].Nickname, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "IK5ZVE/5"
|
|
|
|
|
if loadedLogFile[0].Call != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Call[0] value: %s (expecting %s)", loadedLogFile[0].Call, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "0950"
|
|
|
|
|
if loadedLogFile[0].Time != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Time[0] value: %s (expecting %s)", loadedLogFile[0].Time, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "2020-05-18"
|
|
|
|
|
if loadedLogFile[0].Date != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Date[0] value: %s (expecting %s)", loadedLogFile[0].Date, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "ON6ZQ"
|
|
|
|
|
if loadedLogFile[1].Call != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Call[1] value: %s (expecting %s)", loadedLogFile[1].Call, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "0952"
|
|
|
|
|
if loadedLogFile[1].Time != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Time[1] value: %s (expecting %s)", loadedLogFile[1].Time, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "ON4DO"
|
|
|
|
|
if loadedLogFile[2].Call != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Call[2] value: %s (expecting %s)", loadedLogFile[2].Call, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
expectedValue = "0954"
|
|
|
|
|
if loadedLogFile[2].Time != expectedValue {
|
|
|
|
|
t.Errorf("Not the expected Time[2] value: %s (expecting %s)", loadedLogFile[2].Time, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
//Clean Up
|
|
|
|
|
os.Remove(temporaryDataFileName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestLoadFile_wrongHeader(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
//Given
|
|
|
|
@ -142,7 +304,7 @@ func TestLoadFile_wrongHeader(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
//Then
|
|
|
|
|
if isLoadedOK {
|
|
|
|
|
t.Error("Test file processing should return with aerror")
|
|
|
|
|
t.Error("Test file processing should return with an error")
|
|
|
|
|
}
|
|
|
|
|
if len(loadedLogFile) == 0 {
|
|
|
|
|
t.Error("No data loaded")
|
|
|
|
|