summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/csvwriter.cpp3
-rw-r--r--src/unit/sha1.unit76
2 files changed, 78 insertions, 1 deletions
diff --git a/src/csvwriter.cpp b/src/csvwriter.cpp
index 58437b8..d8910aa 100644
--- a/src/csvwriter.cpp
+++ b/src/csvwriter.cpp
@@ -50,7 +50,7 @@ void Bu::CsvWriter::writeLine( const StrArray &aStrs )
50 50
51Bu::String Bu::CsvWriter::encodeExcel( const Bu::String &sIn ) 51Bu::String Bu::CsvWriter::encodeExcel( const Bu::String &sIn )
52{ 52{
53 if( sIn.find('\"') ) 53 if( sIn.find('\"') || sIn.find(',') )
54 { 54 {
55 Bu::String sOut = "\""; 55 Bu::String sOut = "\"";
56 for( Bu::String::const_iterator i = sIn.begin(); i; i++ ) 56 for( Bu::String::const_iterator i = sIn.begin(); i; i++ )
@@ -60,6 +60,7 @@ Bu::String Bu::CsvWriter::encodeExcel( const Bu::String &sIn )
60 else 60 else
61 sOut += *i; 61 sOut += *i;
62 } 62 }
63 sOut += '\"';
63 return sOut; 64 return sOut;
64 } 65 }
65 return sIn; 66 return sIn;
diff --git a/src/unit/sha1.unit b/src/unit/sha1.unit
new file mode 100644
index 0000000..d91b4c3
--- /dev/null
+++ b/src/unit/sha1.unit
@@ -0,0 +1,76 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2010 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "bu/sha1.h"
10
11#include <stdlib.h>
12
13suite Sha1
14{
15 test basics
16 {
17#define tryStr( a, b ) \
18 { Bu::Sha1 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0
19 tryStr("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
20 tryStr("The quick brown fox jumps over the lazy dog",
21 "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
22 tryStr("The quick brown fox jumps over the lazy cog",
23 "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3");
24 }
25
26 test twoChunks
27 {
28 Bu::Sha1 m;
29 m.addData("The quick brown fo");
30 m.addData("x jumps over the lazy dog");
31 unitTest( m.getHexResult() == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" );
32 }
33
34 test biggerBlocks
35 {
36 const char *sums[41] = {
37 "2356aab95478d8e3c2c918e36f383e46d06154c7",
38 "e3f663240c185a95111c4e00e20865dfbda390aa",
39 "3f21881040b42f44476b610b6d2191f72afc1cb5",
40 "493fe9da6de598c52ea56962b15ccc4405a8dfda",
41 "4684ff568f7c1198a258eb04d88209f4feab4e05",
42 "614101c1c164b8b6099f63165ea01078cbb6c77f",
43 "393f1c1a9f6384653029ab807756e85a13147029",
44 "fd66443d68f8b0508b4f125f2cff1192bfc01913",
45 "1ef66120e530731194554bb2cd51293779a0bcc7",
46 "d77e0eda0037f51b0b6c197371c5fd801cc0eede",
47 "ce8b579bd3aa2ccac2e0205f52a8ed03777117ac",
48 "d9e9d7fc411de2f89329ab758dc8f4302f80ff23"
49 };
50
51 char block[128];
52 for( int i = 0; i < 128; i++ )
53 block[i] = i*2;
54
55 const char **curSum = sums;
56 for( int j = 1; j < 4096; j*=2 )
57 {
58 /*
59 Bu::File fOut("temp", Bu::File::WriteNew );
60 for( int b = 0; b < j; b++ )
61 {
62 fOut.write( block, 128 );
63 }
64 fOut.close();
65 system("sha1sum -b temp");
66 */
67 Bu::Sha1 m;
68 for( int b = 0; b < j; b++ )
69 {
70 m.addData( block, 128 );
71 }
72 unitTest( m.getHexResult() == *curSum );
73 curSum++;
74 }
75 }
76}