Browse code

Updating pwiz to 3_0_21263

Steffen Neumann authored on 23/09/2021 12:34:25
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,181 @@
1
+//
2
+// $Id$
3
+//
4
+//
5
+// Original author: Darren Kessner <darren@proteowizard.org>
6
+//
7
+// Copyright 2007 Spielberg Family Center for Applied Proteomics 
8
+//   Cedars Sinai Medical Center, Los Angeles, California  90048
9
+//
10
+// Licensed under the Apache License, Version 2.0 (the "License"); 
11
+// you may not use this file except in compliance with the License. 
12
+// You may obtain a copy of the License at 
13
+//
14
+// http://www.apache.org/licenses/LICENSE-2.0
15
+//
16
+// Unless required by applicable law or agreed to in writing, software 
17
+// distributed under the License is distributed on an "AS IS" BASIS, 
18
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19
+// See the License for the specific language governing permissions and 
20
+// limitations under the License.
21
+//
22
+
23
+
24
+#include "Std.hpp"
25
+#include "SHA1Calculator.hpp"
26
+#include "unit.hpp"
27
+#include <boost/filesystem/operations.hpp>
28
+#include <cstring>
29
+
30
+
31
+using namespace pwiz::util;
32
+
33
+
34
+ostream* os_ = 0;
35
+
36
+
37
+char verify_int_is_32_bits[(sizeof(int)==4)*2-1];
38
+
39
+
40
+const char* hashEmpty_ = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
41
+
42
+const char* textBrown_ = "The quick brown fox jumps over the lazy dog";
43
+const char* hashBrown_ = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12";
44
+
45
+const char* textabc_ = "abc";
46
+const char* hashabc_ = "a9993e364706816aba3e25717850c26c9cd0d89d";
47
+
48
+const char* textabc2_ = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
49
+const char* hashabc2_ = "84983e441c3bd26ebaae4aa1f95129e5e54670f1";
50
+
51
+const char* hashMillion_ = "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; // one million 'a'
52
+
53
+
54
+void test()
55
+{
56
+    SHA1Calculator sha1;
57
+    sha1.close();
58
+    string temp = sha1.hash();
59
+    if (os_) *os_ << "hash empty: " << temp << endl;
60
+    unit_assert(temp == hashEmpty_);
61
+
62
+    sha1.reset();
63
+    sha1.update((const unsigned char*)textBrown_, strlen(textBrown_));
64
+    sha1.close();
65
+    temp = sha1.hash();
66
+    if (os_) *os_ << "hash brown: " << temp << endl;
67
+    unit_assert(temp == hashBrown_);
68
+}
69
+
70
+
71
+void testStream()
72
+{
73
+    istringstream is(textBrown_);
74
+    string hash = SHA1Calculator::hash(is);
75
+    if (os_) *os_ << "hash stream: " << hash << endl;
76
+    unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
77
+}
78
+
79
+
80
+void testFile()
81
+{
82
+    const char* filename = "sha1test.test.txt";
83
+    ofstream os(filename);
84
+    os << textBrown_; 
85
+    os.close();
86
+
87
+    {
88
+        string hash = SHA1Calculator::hashFile(filename);
89
+        if (os_) *os_ << "hash file: " << hash << endl;
90
+        unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
91
+    }
92
+
93
+    {
94
+        ifstream filestream(filename, ios::binary);
95
+        string hash = SHA1Calculator::hash(filestream);
96
+        if (os_) *os_ << "hash stream: " << hash << endl;
97
+        unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
98
+    }
99
+
100
+    boost::filesystem::remove(filename);
101
+}
102
+
103
+
104
+void testStatic()
105
+{
106
+    string temp = SHA1Calculator::hash(textBrown_);
107
+    unit_assert(temp == hashBrown_);
108
+
109
+    temp = SHA1Calculator::hash(textabc_);
110
+    if (os_) *os_ << "hash abc: " << temp << endl;
111
+    unit_assert(temp == hashabc_);
112
+     
113
+    temp = SHA1Calculator::hash(textabc2_);
114
+    if (os_) *os_ << "hash abc2: " << temp << endl;
115
+    unit_assert(temp == hashabc2_);
116
+}
117
+
118
+
119
+void testMillion()
120
+{
121
+    string a(10, 'a');
122
+    SHA1Calculator sha1;
123
+
124
+    for (int i=0; i<100000; i++)
125
+        sha1.update(a);
126
+    sha1.close();
127
+
128
+    string temp = sha1.hash();
129
+    if (os_) *os_ << "hash million: " << temp << endl;
130
+    unit_assert(temp == hashMillion_);
131
+}
132
+
133
+
134
+void testProjected()
135
+{
136
+    SHA1Calculator sha1;
137
+
138
+    sha1.update((const unsigned char*)textBrown_, strlen(textBrown_));
139
+    string projected = sha1.hashProjected();
140
+    if (os_) *os_ << "projected: " << projected << endl;
141
+
142
+    unit_assert(projected == hashBrown_);
143
+    unit_assert(sha1.hashProjected() == hashBrown_); // doesn't change
144
+
145
+    sha1.close();
146
+    string final = sha1.hash();
147
+    unit_assert(final == hashBrown_);
148
+    unit_assert(sha1.hash() == hashBrown_); // doesn't change
149
+}
150
+
151
+
152
+int main(int argc, char* argv[])
153
+{
154
+    TEST_PROLOG(argc, argv)
155
+
156
+    try
157
+    {
158
+        if (argc>1 && !strcmp(argv[1],"-v")) // verbose
159
+            os_ = &cout;
160
+
161
+        if (os_) *os_ << "sha1test\n";
162
+
163
+        test();
164
+        testStream();
165
+        testFile();
166
+        testStatic();
167
+        testMillion();
168
+        testProjected();
169
+    }
170
+    catch (exception& e)
171
+    {
172
+        TEST_FAILED(e.what())
173
+    }
174
+    catch (...)
175
+    {
176
+        TEST_FAILED("Caught unknown exception.")
177
+    }
178
+
179
+    TEST_EPILOG
180
+}
181
+
Browse code

Removed old pwiz code

Steffen Neumann authored on 22/09/2021 10:40:31
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,181 +0,0 @@
1
-//
2
-// $Id: SHA1CalculatorTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3
-//
4
-//
5
-// Original author: Darren Kessner <darren@proteowizard.org>
6
-//
7
-// Copyright 2007 Spielberg Family Center for Applied Proteomics 
8
-//   Cedars Sinai Medical Center, Los Angeles, California  90048
9
-//
10
-// Licensed under the Apache License, Version 2.0 (the "License"); 
11
-// you may not use this file except in compliance with the License. 
12
-// You may obtain a copy of the License at 
13
-//
14
-// http://www.apache.org/licenses/LICENSE-2.0
15
-//
16
-// Unless required by applicable law or agreed to in writing, software 
17
-// distributed under the License is distributed on an "AS IS" BASIS, 
18
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19
-// See the License for the specific language governing permissions and 
20
-// limitations under the License.
21
-//
22
-
23
-
24
-#include "Std.hpp"
25
-#include "SHA1Calculator.hpp"
26
-#include "unit.hpp"
27
-#include <boost/filesystem/operations.hpp>
28
-#include <cstring>
29
-
30
-
31
-using namespace pwiz::util;
32
-
33
-
34
-ostream* os_ = 0;
35
-
36
-
37
-char verify_int_is_32_bits[(sizeof(int)==4)*2-1];
38
-
39
-
40
-const char* hashEmpty_ = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
41
-
42
-const char* textBrown_ = "The quick brown fox jumps over the lazy dog";
43
-const char* hashBrown_ = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12";
44
-
45
-const char* textabc_ = "abc";
46
-const char* hashabc_ = "a9993e364706816aba3e25717850c26c9cd0d89d";
47
-
48
-const char* textabc2_ = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
49
-const char* hashabc2_ = "84983e441c3bd26ebaae4aa1f95129e5e54670f1";
50
-
51
-const char* hashMillion_ = "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; // one million 'a'
52
-
53
-
54
-void test()
55
-{
56
-    SHA1Calculator sha1;
57
-    sha1.close();
58
-    string temp = sha1.hash();
59
-    if (os_) *os_ << "hash empty: " << temp << endl;
60
-    unit_assert(temp == hashEmpty_);
61
-
62
-    sha1.reset();
63
-    sha1.update((const unsigned char*)textBrown_, strlen(textBrown_));
64
-    sha1.close();
65
-    temp = sha1.hash();
66
-    if (os_) *os_ << "hash brown: " << temp << endl;
67
-    unit_assert(temp == hashBrown_);
68
-}
69
-
70
-
71
-void testStream()
72
-{
73
-    istringstream is(textBrown_);
74
-    string hash = SHA1Calculator::hash(is);
75
-    if (os_) *os_ << "hash stream: " << hash << endl;
76
-    unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
77
-}
78
-
79
-
80
-void testFile()
81
-{
82
-    const char* filename = "sha1test.test.txt";
83
-    ofstream os(filename);
84
-    os << textBrown_; 
85
-    os.close();
86
-
87
-    {
88
-        string hash = SHA1Calculator::hashFile(filename);
89
-        if (os_) *os_ << "hash file: " << hash << endl;
90
-        unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
91
-    }
92
-
93
-    {
94
-        ifstream filestream(filename, ios::binary);
95
-        string hash = SHA1Calculator::hash(filestream);
96
-        if (os_) *os_ << "hash stream: " << hash << endl;
97
-        unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
98
-    }
99
-
100
-    boost::filesystem::remove(filename);
101
-}
102
-
103
-
104
-void testStatic()
105
-{
106
-    string temp = SHA1Calculator::hash(textBrown_);
107
-    unit_assert(temp == hashBrown_);
108
-
109
-    temp = SHA1Calculator::hash(textabc_);
110
-    if (os_) *os_ << "hash abc: " << temp << endl;
111
-    unit_assert(temp == hashabc_);
112
-     
113
-    temp = SHA1Calculator::hash(textabc2_);
114
-    if (os_) *os_ << "hash abc2: " << temp << endl;
115
-    unit_assert(temp == hashabc2_);
116
-}
117
-
118
-
119
-void testMillion()
120
-{
121
-    string a(10, 'a');
122
-    SHA1Calculator sha1;
123
-
124
-    for (int i=0; i<100000; i++)
125
-        sha1.update(a);
126
-    sha1.close();
127
-
128
-    string temp = sha1.hash();
129
-    if (os_) *os_ << "hash million: " << temp << endl;
130
-    unit_assert(temp == hashMillion_);
131
-}
132
-
133
-
134
-void testProjected()
135
-{
136
-    SHA1Calculator sha1;
137
-
138
-    sha1.update((const unsigned char*)textBrown_, strlen(textBrown_));
139
-    string projected = sha1.hashProjected();
140
-    if (os_) *os_ << "projected: " << projected << endl;
141
-
142
-    unit_assert(projected == hashBrown_);
143
-    unit_assert(sha1.hashProjected() == hashBrown_); // doesn't change
144
-
145
-    sha1.close();
146
-    string final = sha1.hash();
147
-    unit_assert(final == hashBrown_);
148
-    unit_assert(sha1.hash() == hashBrown_); // doesn't change
149
-}
150
-
151
-
152
-int main(int argc, char* argv[])
153
-{
154
-    TEST_PROLOG(argc, argv)
155
-
156
-    try
157
-    {
158
-        if (argc>1 && !strcmp(argv[1],"-v")) // verbose
159
-            os_ = &cout;
160
-
161
-        if (os_) *os_ << "sha1test\n";
162
-
163
-        test();
164
-        testStream();
165
-        testFile();
166
-        testStatic();
167
-        testMillion();
168
-        testProjected();
169
-    }
170
-    catch (exception& e)
171
-    {
172
-        TEST_FAILED(e.what())
173
-    }
174
-    catch (...)
175
-    {
176
-        TEST_FAILED("Caught unknown exception.")
177
-    }
178
-
179
-    TEST_EPILOG
180
-}
181
-
Browse code

Mavericks support

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/mzR@90716 bc3139a8-67e5-0310-9ffc-ced21a209358

l.gatto authored on 26/05/2014 19:55:15
Showing1 changed files
... ...
@@ -1,5 +1,5 @@
1 1
 //
2
-// $Id: SHA1CalculatorTest.cpp 2051 2010-06-15 18:39:13Z chambm $
2
+// $Id: SHA1CalculatorTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3 3
 //
4 4
 //
5 5
 // Original author: Darren Kessner <darren@proteowizard.org>
... ...
@@ -21,10 +21,10 @@
21 21
 //
22 22
 
23 23
 
24
+#include "Std.hpp"
24 25
 #include "SHA1Calculator.hpp"
25 26
 #include "unit.hpp"
26 27
 #include <boost/filesystem/operations.hpp>
27
-#include "pwiz/utility/misc/Std.hpp"
28 28
 #include <cstring>
29 29
 
30 30
 
... ...
@@ -72,7 +72,7 @@ void testStream()
72 72
 {
73 73
     istringstream is(textBrown_);
74 74
     string hash = SHA1Calculator::hash(is);
75
-    if (os_) *os_ << "hash file: " << hash << endl;
75
+    if (os_) *os_ << "hash stream: " << hash << endl;
76 76
     unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
77 77
 }
78 78
 
... ...
@@ -84,9 +84,18 @@ void testFile()
84 84
     os << textBrown_; 
85 85
     os.close();
86 86
 
87
-    string hash = SHA1Calculator::hashFile(filename);
88
-    if (os_) *os_ << "hash file: " << hash << endl;
89
-    unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
87
+    {
88
+        string hash = SHA1Calculator::hashFile(filename);
89
+        if (os_) *os_ << "hash file: " << hash << endl;
90
+        unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
91
+    }
92
+
93
+    {
94
+        ifstream filestream(filename, ios::binary);
95
+        string hash = SHA1Calculator::hash(filestream);
96
+        if (os_) *os_ << "hash stream: " << hash << endl;
97
+        unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
98
+    }
90 99
 
91 100
     boost::filesystem::remove(filename);
92 101
 }
... ...
@@ -142,6 +151,8 @@ void testProjected()
142 151
 
143 152
 int main(int argc, char* argv[])
144 153
 {
154
+    TEST_PROLOG(argc, argv)
155
+
145 156
     try
146 157
     {
147 158
         if (argc>1 && !strcmp(argv[1],"-v")) // verbose
... ...
@@ -155,12 +166,16 @@ int main(int argc, char* argv[])
155 166
         testStatic();
156 167
         testMillion();
157 168
         testProjected();
158
-        return 0;
159 169
     }
160 170
     catch (exception& e)
161 171
     {
162
-        cerr << e.what() << endl;
163
-        return 1;
172
+        TEST_FAILED(e.what())
164 173
     }
174
+    catch (...)
175
+    {
176
+        TEST_FAILED("Caught unknown exception.")
177
+    }
178
+
179
+    TEST_EPILOG
165 180
 }
166 181
 
Browse code

Added the mzR package to the repository.

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/mzR@57456 bc3139a8-67e5-0310-9ffc-ced21a209358

c.wong authored on 15/08/2011 19:53:29
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,166 @@
1
+//
2
+// $Id: SHA1CalculatorTest.cpp 2051 2010-06-15 18:39:13Z chambm $
3
+//
4
+//
5
+// Original author: Darren Kessner <darren@proteowizard.org>
6
+//
7
+// Copyright 2007 Spielberg Family Center for Applied Proteomics 
8
+//   Cedars Sinai Medical Center, Los Angeles, California  90048
9
+//
10
+// Licensed under the Apache License, Version 2.0 (the "License"); 
11
+// you may not use this file except in compliance with the License. 
12
+// You may obtain a copy of the License at 
13
+//
14
+// http://www.apache.org/licenses/LICENSE-2.0
15
+//
16
+// Unless required by applicable law or agreed to in writing, software 
17
+// distributed under the License is distributed on an "AS IS" BASIS, 
18
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19
+// See the License for the specific language governing permissions and 
20
+// limitations under the License.
21
+//
22
+
23
+
24
+#include "SHA1Calculator.hpp"
25
+#include "unit.hpp"
26
+#include <boost/filesystem/operations.hpp>
27
+#include "pwiz/utility/misc/Std.hpp"
28
+#include <cstring>
29
+
30
+
31
+using namespace pwiz::util;
32
+
33
+
34
+ostream* os_ = 0;
35
+
36
+
37
+char verify_int_is_32_bits[(sizeof(int)==4)*2-1];
38
+
39
+
40
+const char* hashEmpty_ = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
41
+
42
+const char* textBrown_ = "The quick brown fox jumps over the lazy dog";
43
+const char* hashBrown_ = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12";
44
+
45
+const char* textabc_ = "abc";
46
+const char* hashabc_ = "a9993e364706816aba3e25717850c26c9cd0d89d";
47
+
48
+const char* textabc2_ = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
49
+const char* hashabc2_ = "84983e441c3bd26ebaae4aa1f95129e5e54670f1";
50
+
51
+const char* hashMillion_ = "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; // one million 'a'
52
+
53
+
54
+void test()
55
+{
56
+    SHA1Calculator sha1;
57
+    sha1.close();
58
+    string temp = sha1.hash();
59
+    if (os_) *os_ << "hash empty: " << temp << endl;
60
+    unit_assert(temp == hashEmpty_);
61
+
62
+    sha1.reset();
63
+    sha1.update((const unsigned char*)textBrown_, strlen(textBrown_));
64
+    sha1.close();
65
+    temp = sha1.hash();
66
+    if (os_) *os_ << "hash brown: " << temp << endl;
67
+    unit_assert(temp == hashBrown_);
68
+}
69
+
70
+
71
+void testStream()
72
+{
73
+    istringstream is(textBrown_);
74
+    string hash = SHA1Calculator::hash(is);
75
+    if (os_) *os_ << "hash file: " << hash << endl;
76
+    unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
77
+}
78
+
79
+
80
+void testFile()
81
+{
82
+    const char* filename = "sha1test.test.txt";
83
+    ofstream os(filename);
84
+    os << textBrown_; 
85
+    os.close();
86
+
87
+    string hash = SHA1Calculator::hashFile(filename);
88
+    if (os_) *os_ << "hash file: " << hash << endl;
89
+    unit_assert(hash == "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
90
+
91
+    boost::filesystem::remove(filename);
92
+}
93
+
94
+
95
+void testStatic()
96
+{
97
+    string temp = SHA1Calculator::hash(textBrown_);
98
+    unit_assert(temp == hashBrown_);
99
+
100
+    temp = SHA1Calculator::hash(textabc_);
101
+    if (os_) *os_ << "hash abc: " << temp << endl;
102
+    unit_assert(temp == hashabc_);
103
+     
104
+    temp = SHA1Calculator::hash(textabc2_);
105
+    if (os_) *os_ << "hash abc2: " << temp << endl;
106
+    unit_assert(temp == hashabc2_);
107
+}
108
+
109
+
110
+void testMillion()
111
+{
112
+    string a(10, 'a');
113
+    SHA1Calculator sha1;
114
+
115
+    for (int i=0; i<100000; i++)
116
+        sha1.update(a);
117
+    sha1.close();
118
+
119
+    string temp = sha1.hash();
120
+    if (os_) *os_ << "hash million: " << temp << endl;
121
+    unit_assert(temp == hashMillion_);
122
+}
123
+
124
+
125
+void testProjected()
126
+{
127
+    SHA1Calculator sha1;
128
+
129
+    sha1.update((const unsigned char*)textBrown_, strlen(textBrown_));
130
+    string projected = sha1.hashProjected();
131
+    if (os_) *os_ << "projected: " << projected << endl;
132
+
133
+    unit_assert(projected == hashBrown_);
134
+    unit_assert(sha1.hashProjected() == hashBrown_); // doesn't change
135
+
136
+    sha1.close();
137
+    string final = sha1.hash();
138
+    unit_assert(final == hashBrown_);
139
+    unit_assert(sha1.hash() == hashBrown_); // doesn't change
140
+}
141
+
142
+
143
+int main(int argc, char* argv[])
144
+{
145
+    try
146
+    {
147
+        if (argc>1 && !strcmp(argv[1],"-v")) // verbose
148
+            os_ = &cout;
149
+
150
+        if (os_) *os_ << "sha1test\n";
151
+
152
+        test();
153
+        testStream();
154
+        testFile();
155
+        testStatic();
156
+        testMillion();
157
+        testProjected();
158
+        return 0;
159
+    }
160
+    catch (exception& e)
161
+    {
162
+        cerr << e.what() << endl;
163
+        return 1;
164
+    }
165
+}
166
+