Skip to content

Commit e84b573

Browse files
Unit test experiment - these were written by codex (#335)
Added BaseTypeTest.cc. Fixed my hack to include DAPCache3Test w/o adding it to the library. Co-authored-by: Hannah Robertson <hannahilea@users.noreply.github.com>
1 parent 83ce4f0 commit e84b573

16 files changed

Lines changed: 948 additions & 73 deletions

‎.gitignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.project
99
.settings
1010
.DS_Store
11+
.vscode/
1112
*/.DS_Store
1213
gcovr-output/
1314
gcov-data/
@@ -74,6 +75,7 @@ libtool
7475
doxy.conf
7576
doxygen_warnings.txt
7677
main_page.doxygen
78+
dmr_memory_cache
7779

7880
## libdap specific files
7981
gl/*.h
@@ -201,6 +203,14 @@ unit-tests/GridTest
201203
unit-tests/IsDap4ProjectedTest
202204
unit-tests/util_mitTest
203205
unit-tests/MarshallerFutureTest
206+
unit-tests/BaseTypeTest
207+
unit-tests/ConstraintEvaluatorTest
208+
unit-tests/D4StreamRoundTripTest
209+
unit-tests/DAPCache3Test
210+
unit-tests/ErrorTest
211+
unit-tests/MarshallerThreadTest
212+
unit-tests/dmr_memory_cache
213+
unit-tests/dapcache3test.*
204214

205215
d4_ce/unit-tests/D4ConstraintEvaluatorTest
206216
d4_ce/unit-tests/test_config.h

‎DAPCache3.h‎

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,18 @@
2929
#ifndef DAPCache3_h_
3030
#define DAPCache3_h_ 1
3131

32-
// #include <algorithm>
3332
#include <list>
3433
#include <map>
3534
#include <string>
36-
// #include <sstream>
3735

3836
#include "DapObj.h"
3937

40-
#if 0
41-
#include "BESDebug.h"
42-
#include "BESObj.h"
43-
44-
class BESKeys;
45-
#endif
46-
4738
namespace libdap {
4839

4940
// These typedefs are used to record information about the files in the cache.
5041
// See DAPCache3.cc and look at the purge() method.
5142
typedef struct {
52-
string name;
43+
std::string name;
5344
unsigned long long size;
5445
time_t time;
5546
} cache_entry;
@@ -80,25 +71,19 @@ typedef std::list<cache_entry> CacheFiles;
8071
* on the cache info file must only be called when the lock has been obtained.
8172
*/
8273
class DAPCache3 : public libdap::DapObj {
83-
84-
private:
8574
static DAPCache3 *d_instance;
8675

8776
static const char DAP_CACHE_CHAR = '#';
8877

89-
string d_cache_dir; /// pathname of the cache directory
90-
string d_prefix; /// tack this on the front of cache file name
78+
std::string d_cache_dir; /// pathname of the cache directory
79+
std::string d_prefix; /// tack this on the front of cache file name
9180

9281
/// How many megabytes can the cache hold before we have to purge
9382
unsigned long long d_max_cache_size_in_bytes;
9483
// When we purge, how much should we throw away. Set in the ctor to 80% of the max size.
9584
unsigned long long d_target_size;
96-
#if 0
97-
// This class implements a singleton, so the constructor is hidden.
98-
BESCache3(BESKeys *keys, const string &cache_dir_key, const string &prefix_key, const string &size_key);
99-
#endif
10085
// Testing
101-
DAPCache3(const string &cache_dir, const string &prefix, unsigned long long size);
86+
DAPCache3(const std::string &cache_dir, const std::string &prefix, unsigned long long size);
10287

10388
// Suppress the assignment operator and default copy ctor, ...
10489
DAPCache3();
@@ -111,47 +96,43 @@ class DAPCache3 : public libdap::DapObj {
11196
unsigned long long m_collect_cache_dir_info(CacheFiles &contents);
11297

11398
/// Name of the file that tracks the size of the cache
114-
string d_cache_info;
99+
std::string d_cache_info;
115100
int d_cache_info_fd;
116101

117-
void m_record_descriptor(const string &file, int fd);
118-
int m_get_descriptor(const string &file);
102+
void m_record_descriptor(const std::string &file, int fd);
103+
int m_get_descriptor(const std::string &file);
119104

120105
// map that relates files to the descriptor used to obtain a lock
121-
typedef std::map<string, int> FilesAndLockDescriptors;
106+
typedef std::map<std::string, int> FilesAndLockDescriptors;
122107
FilesAndLockDescriptors d_locks;
123108

124109
// Life-cycle control
125-
virtual ~DAPCache3() {}
110+
~DAPCache3() override {}
126111
static void delete_instance();
127112

128113
public:
129-
static DAPCache3 *get_instance(const string &cache_dir, const string &prefix, unsigned long long size);
114+
static DAPCache3 *get_instance(const std::string &cache_dir, const std::string &prefix, unsigned long long size);
130115
static DAPCache3 *get_instance();
131116

132-
string get_cache_file_name(const string &src, bool mangle = true);
117+
std::string get_cache_file_name(const std::string &src, bool mangle = true);
133118

134-
virtual bool create_and_lock(const string &target, int &fd);
135-
virtual bool get_read_lock(const string &target, int &fd);
119+
virtual bool create_and_lock(const std::string &target, int &fd);
120+
virtual bool get_read_lock(const std::string &target, int &fd);
136121
virtual void exclusive_to_shared_lock(int fd);
137-
virtual void unlock_and_close(const string &target);
122+
virtual void unlock_and_close(const std::string &target);
138123
virtual void unlock_and_close(int fd);
139124

140125
virtual void lock_cache_write();
141126
virtual void lock_cache_read();
142127
virtual void unlock_cache();
143128

144-
virtual unsigned long long update_cache_info(const string &target);
129+
virtual unsigned long long update_cache_info(const std::string &target);
145130
virtual bool cache_too_big(unsigned long long current_size) const;
146131
virtual unsigned long long get_cache_size();
147-
virtual void update_and_purge(const string &new_file);
148-
virtual void purge_file(const string &file);
149-
150-
#if 0
151-
static BESCache3 *get_instance(BESKeys *keys, const string &cache_dir_key, const string &prefix_key, const string &size_key);
152-
#endif
132+
virtual void update_and_purge(const std::string &new_file);
133+
virtual void purge_file(const std::string &file);
153134

154-
void dump(ostream &strm) const override;
135+
void dump(std::ostream &strm) const override;
155136
};
156137

157138
} // namespace libdap

‎Makefile.am‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ dmr_memory_cache_SOURCES = dmr_mcache_test.cc
8787
dmr_memory_cache_LDADD = libdapclient.la libdap.la
8888
dmr_memory_cache_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/http_dap $(CURL_CFLAGS)
8989

90-
91-
9290
LEX_YACC_EXTRA = das.lex das.yy dds.lex dds.yy ce_expr.lex ce_expr.yy \
9391
Error.lex Error.yy
9492

@@ -132,7 +130,6 @@ cccc:
132130
# dist-hook:
133131
# if test -n "$$VERSION"; then cat $$VERSION NEWS > NEWS.tmp; mv NEWS.tmp NEWS; fi
134132

135-
136133
# Build linux RPMs. Use the environment variable 'RPM_OPTIONS' to pass in
137134
# extra options like --nodeps and --macros
138135

‎parser-util.cc‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ int check_uint32(const char *val, unsigned int &v) {
339339
return FALSE;
340340
}
341341
// See above.
342-
else if (tmp > DODS_UINT_MAX) {
342+
if (tmp > DODS_UINT_MAX) {
343343
return FALSE;
344-
} else {
345-
v = (unsigned int)tmp;
346-
return TRUE;
347344
}
345+
346+
v = (unsigned int)tmp;
347+
return TRUE;
348348
}
349349

350350
int check_int64(const char *val) {
@@ -362,19 +362,8 @@ int check_int64(const char *val) {
362362
if (errno == ERANGE) {
363363
return FALSE;
364364
}
365-
#if 0
366-
// This could be combined with the above, or course, but I'm making it
367-
// separate to highlight the test. On 64-bit linux boxes 'long' may be
368-
// 64-bits and so 'v' can hold more than a DODS_INT32. jhrg 3/23/10
369-
//
370-
// Removed - Coverity says it can never be false. Makes sense. jhrg 5/10/16
371-
else if (v <= DODS_LLONG_MAX && v >= DODS_LLONG_MIN) {
372-
return FALSE;
373-
}
374-
#endif
375-
else {
376-
return TRUE;
377-
}
365+
366+
return TRUE;
378367
}
379368

380369
int check_uint64(const char *val) {
@@ -398,11 +387,13 @@ int check_uint64(const char *val) {
398387

399388
if (errno == ERANGE) {
400389
return FALSE;
401-
} else if (v > DODS_ULLONG_MAX) { // 2^61
390+
}
391+
392+
if (v > DODS_ULLONG_MAX) { // 2^61
402393
return FALSE;
403-
} else {
404-
return v;
405394
}
395+
396+
return TRUE;
406397
}
407398

408399
// Check first for system errors (like numbers so small they convert

‎retired/VCPP/BeforeInstall.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
In addition to installing libdap 3.8.2, this will also install other run-time libraries libdap uses. However, this will not install the software need to compile our source code on the Windows XP platform. For more information about building our software from source, see http://scm.opendap.org/trac/wiki/XP or contact us at support at opendap.org.
1+
In addition to installing libdap 3.8.2, this will also install other run-time libraries libdap uses. However, this will not install the software need to compile our source code on the Windows XP platform. For more information about building our software from source, see http://scm.opendap.org/trac/wiki/XP or contact us at support at opendap.org.

‎unit-tests/ArrayTest.cc‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class ArrayTest : public TestFixture {
149149
CPPUNIT_TEST(duplicate_cardinal_test);
150150
CPPUNIT_TEST(duplicate_string_test);
151151
CPPUNIT_TEST(duplicate_structure_test);
152+
CPPUNIT_TEST(zero_length_array_test);
153+
CPPUNIT_TEST(deep_copy_cardinal_test);
152154

153155
CPPUNIT_TEST_SUITE_END();
154156

@@ -324,6 +326,37 @@ class ArrayTest : public TestFixture {
324326
a = 0;
325327
}
326328

329+
void zero_length_array_test() {
330+
Int16 i16("i16");
331+
Array a("zero_len", &i16);
332+
a.append_dim(0, "empty");
333+
CPPUNIT_ASSERT_EQUAL(0, a.length());
334+
CPPUNIT_ASSERT_EQUAL((int64_t)0, a.length_ll());
335+
CPPUNIT_ASSERT_EQUAL((unsigned int)0, a.width());
336+
CPPUNIT_ASSERT_EQUAL((int64_t)0, a.width_ll());
337+
}
338+
339+
void deep_copy_cardinal_test() {
340+
Int16 i16("i16");
341+
Array a1("a1", &i16);
342+
a1.append_dim(4, "d0");
343+
344+
dods_int16 v1[4] = {10, 20, 30, 40};
345+
a1.set_value(v1, 4);
346+
347+
Array a2(a1);
348+
349+
dods_int16 v2[4] = {1, 2, 3, 4};
350+
a1.set_value(v2, 4);
351+
352+
dods_int16 out[4] = {0, 0, 0, 0};
353+
a2.value(out);
354+
CPPUNIT_ASSERT(out[0] == 10);
355+
CPPUNIT_ASSERT(out[1] == 20);
356+
CPPUNIT_ASSERT(out[2] == 30);
357+
CPPUNIT_ASSERT(out[3] == 40);
358+
}
359+
327360
void duplicate_string_test() {
328361
Array::Dim_iter i = d_string->dim_begin();
329362
CPPUNIT_ASSERT(d_string->dimension_size(i) == 4);

0 commit comments

Comments
 (0)