diff options
author | bradnelson@google.com <bradnelson@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-28 20:23:26 +0000 |
---|---|---|
committer | bradnelson@google.com <bradnelson@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-28 20:23:26 +0000 |
commit | d15f03f7d3aaa253d32c8bfc4f1543f5f9d6eeae (patch) | |
tree | e3ae9df25c03721d2889ca4aad346dc7c2d99363 /o3d/utils/cross | |
parent | e6111af1609505398801eed7619a2f7191fe3a2b (diff) | |
download | chromium_src-d15f03f7d3aaa253d32c8bfc4f1543f5f9d6eeae.zip chromium_src-d15f03f7d3aaa253d32c8bfc4f1543f5f9d6eeae.tar.gz chromium_src-d15f03f7d3aaa253d32c8bfc4f1543f5f9d6eeae.tar.bz2 |
Moving o3d up a level, to get it out of chrome checkouts.
BUG=None
TEST=None
Too large for codereview.
Manual review by thaloun and tschelcher.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/utils/cross')
34 files changed, 0 insertions, 4217 deletions
diff --git a/o3d/utils/cross/base64.cc b/o3d/utils/cross/base64.cc deleted file mode 100644 index 0d36e1e..0000000 --- a/o3d/utils/cross/base64.cc +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// This file contains the declaration of functions for dealing with base64 -// encoding and decoding - -#include "utils/cross/base64.h" -#include "core/cross/types.h" - -namespace o3d { -namespace base64 { - -size_t GetEncodeLength(size_t length) { - return (length + 2) / 3 * 4; -} - -void Encode(const void* src_ptr, size_t length, void* dst_ptr) { - const int kEncodePad = 64; - - static const char kEncode[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/="; - - const uint8* src = reinterpret_cast<const uint8*>(src_ptr); - uint8* dst = reinterpret_cast<uint8*>(dst_ptr); - if (dst) { - size_t remainder = length % 3; - const uint8* end = &src[length - remainder]; - while (src < end) { - unsigned a = *src++; - unsigned b = *src++; - unsigned c = *src++; - unsigned d = c & 0x3F; - c = (c >> 6 | b << 2) & 0x3F; - b = (b >> 4 | a << 4) & 0x3F; - a = a >> 2; - *dst++ = kEncode[a]; - *dst++ = kEncode[b]; - *dst++ = kEncode[c]; - *dst++ = kEncode[d]; - } - if (remainder > 0) { - unsigned k1 = 0; - unsigned k2 = kEncodePad; - unsigned a = *src++; - if (remainder == 2) { - int b = *src++; - k1 = b >> 4; - k2 = (b << 2) & 0x3F; - } - *dst++ = kEncode[a >> 2]; - *dst++ = kEncode[(k1 | a << 4) & 0x3F]; - *dst++ = kEncode[k2]; - *dst++ = kEncode[kEncodePad]; - } - } -} - -// This function actually does the decoding. -// Parameters: -// src_ptr: pointer to the source data -// input_length: The length in bytes of the source data. -// dst_ptr: pointer to where the output data should be stored. -// dst_buffer_length: the size in bytes of the dst_ptr buffer. This -// is used to check for overflow. Not used if write_destination is -// false. -// output_length: The output length (in bytes) will be stored here if -// it is not null. -// write_destination: If true, actually write to the output. Otherwise, -// the length of the output will be determined only. -DecodeStatus PerformDecode(const void* src_ptr, - size_t input_length, - void* dst_ptr, - size_t dst_buffer_length, - size_t* output_length, - bool write_destination) { - const int kDecodePad = -2; - - static const int8 kDecodeData[] = { - 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, kDecodePad, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 - }; - - uint8* dst = reinterpret_cast<uint8*>(dst_ptr); - const uint8* dst_start = reinterpret_cast<const uint8*>(dst_ptr); - const uint8* dst_end = dst_start + dst_buffer_length; - const uint8* src = reinterpret_cast<const uint8*>(src_ptr); - bool pad_two = false; - bool pad_three = false; - const uint8* end = src + input_length; - while (src < end) { - uint8 bytes[4]; - int byte = 0; - do { - uint8 src_byte = *src++; - if (src_byte == 0) - goto goHome; - if (src_byte <= ' ') - continue; // treat as white space - if (src_byte < '+' || src_byte > 'z') - return kBadCharError; - int8 decoded = kDecodeData[src_byte - '+']; - bytes[byte] = decoded; - if (decoded < 0) { - if (decoded == kDecodePad) - goto handlePad; - return kBadCharError; - } else { - byte++; - } - if (*src) - continue; - if (byte == 0) - goto goHome; - if (byte == 4) - break; - handlePad: - if (byte < 2) - return kPadError; - pad_three = true; - if (byte == 2) - pad_two = true; - break; - } while (byte < 4); - int two = 0, three = 0; - if (write_destination) { - int one = (bytes[0] << 2) & 0xFF; - two = bytes[1]; - one |= two >> 4; - two = (two << 4) & 0xFF; - three = bytes[2]; - two |= three >> 2; - three = (three << 6) & 0xFF; - three |= bytes[3]; - O3D_ASSERT(one < 256 && two < 256 && three < 256); - if (dst >= dst_end) { - return kOutputOverflowError; - } - *dst = one; - } - dst++; - if (pad_two) - break; - if (write_destination) { - if (dst >= dst_end) { - return kOutputOverflowError; - } - *dst = two; - } - dst++; - if (pad_three) - break; - if (write_destination) { - if (dst >= dst_end) { - return kOutputOverflowError; - } - *dst = three; - } - dst++; - } - goHome: - if (output_length) { - *output_length = dst - dst_start; - } - return kSuccess; -} - -// Returns the number of bytes of output data after decoding from base64. -DecodeStatus GetDecodeLength(const void* src, - size_t input_length, - size_t* decode_length) { - return PerformDecode(src, input_length, NULL, 0, decode_length, false); -} - -// Decodes the src data from base64 and stores the result in dst. -DecodeStatus Decode(const void* src, - size_t input_length, - void* dst, - size_t dst_buffer_length) { - return PerformDecode(src, input_length, dst, dst_buffer_length, NULL, true); -} - -} // namespace base64 -} // namespace o3d - diff --git a/o3d/utils/cross/base64.h b/o3d/utils/cross/base64.h deleted file mode 100644 index eae0817..0000000 --- a/o3d/utils/cross/base64.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// This file contains the declaration of functions for dealing with base64 -// encoding and decoding - -#ifndef O3D_UTILS_CROSS_BASE64_H_ -#define O3D_UTILS_CROSS_BASE64_H_ - -#include <stddef.h> - -namespace o3d { -namespace base64 { - -// The possible error codes that can occur during a decoding. -enum DecodeStatus { - kSuccess, - kPadError, - kBadCharError, - kOutputOverflowError -}; - -// Returns the number of bytes needed to encode length bytes in base64. -size_t GetEncodeLength(size_t length); - -// Encodes the src into base64 into the dst. The dst must have enough -// space to hold the result. -// Parameters: -// src: pointer to source data. -// length: the length of the source data -// dst: pointer to place to store result. -void Encode(const void* src, size_t length, void* dst); - -// Used to obtain the number of bytes needed to decode the src data -// from base64. -// Parameters: -// src: pointer to the source data. -// input_length: the length of the source data -// decode_length: the length in bytes of the decoded data will be -// placed here. -DecodeStatus GetDecodeLength(const void* src, - size_t input_length, - size_t* decode_length); - -// Decodes the src, which should be encoded in base64, into the dst. -// dst must have enough space to hold the result. The number of bytes -// necessary can be obtained by calling GetDecodeLength() -// Parameters: -// src: pointer to the source data -// input_length: the length of the source data -// dst: pointer to where the result should be stored. -// dst_buffer_length: the size in bytes of the dst buffer. This is -// used to check for buffer overflow. -// Returns an error code (of type DecodeStatus) -DecodeStatus Decode(const void* src, - size_t input_length, - void* dst, - size_t dst_buffer_length); - -} // namespace base64 -} // namespace o3d - -#endif // O3D_UTILS_CROSS_BASE64_H_ - diff --git a/o3d/utils/cross/base64_test.cc b/o3d/utils/cross/base64_test.cc deleted file mode 100644 index d291f14..0000000 --- a/o3d/utils/cross/base64_test.cc +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of base64 functions - -#include "tests/common/win/testing_common.h" -#include "utils/cross/base64.h" - -namespace o3d { - -class Base64Test : public testing::Test { -}; - -TEST_F(Base64Test, GetEncodeLength) { - EXPECT_EQ(0u, base64::GetEncodeLength(0)); - EXPECT_EQ(4u, base64::GetEncodeLength(1)); - EXPECT_EQ(4u, base64::GetEncodeLength(2)); - EXPECT_EQ(4u, base64::GetEncodeLength(3)); - EXPECT_EQ(8u, base64::GetEncodeLength(4)); -} - -TEST_F(Base64Test, Encode) { - unsigned char buffer[100]; - memset(buffer, 0xFF, sizeof(buffer)); - base64::Encode("abc", 3, buffer); - EXPECT_EQ(0, memcmp(buffer, "YWJj", 4)); - EXPECT_EQ(0xFF, buffer[4]); - memset(buffer, 0xFF, sizeof(buffer)); - base64::Encode("ab\0c", 4, buffer); - EXPECT_EQ(0, memcmp(buffer, "YWIAYw==", 8)); - EXPECT_EQ(0xFF, buffer[8]); -} - -TEST_F(Base64Test, GetDecodeLength) { - size_t length = 256u; - base64::GetDecodeLength("", 0, &length); - EXPECT_EQ(0u, length); - - length = 256u; - base64::GetDecodeLength("YQ==", 4, &length); - EXPECT_EQ(1u, length); - - length = 256u; - base64::GetDecodeLength("YWI=", 4, &length); - EXPECT_EQ(2u, length); - - length = 256u; - base64::GetDecodeLength("YWJj", 4, &length); - EXPECT_EQ(3u, length); - - length = 256u; - base64::GetDecodeLength("YWJjZA==", 8, &length); - EXPECT_EQ(4u, length); - - length = 256u; - base64::GetDecodeLength("YWJjZGU=", 8, &length); - EXPECT_EQ(5u, length); -} - -TEST_F(Base64Test, GetDecodeLengthInputError) { - base64::DecodeStatus status = base64::kSuccess; - size_t length = 256u; - status = base64::GetDecodeLength("Y@==", 4, &length); - EXPECT_EQ(base64::kBadCharError, status); - - status = base64::GetDecodeLength("Y Q==", 4, &length); - EXPECT_EQ(base64::kSuccess, status); - - status = base64::GetDecodeLength("Y", 1, &length); - EXPECT_EQ(base64::kPadError, status); -} - -TEST_F(Base64Test, Decode) { - unsigned char buffer[10]; - memset(buffer, 0xFF, sizeof(buffer)); - unsigned char result_buffer[10]; - memset(result_buffer, 0xFF, sizeof(result_buffer)); - base64::DecodeStatus status = base64::kSuccess; - - status = base64::Decode("", 0, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); - - result_buffer[0] = 'a'; - status = base64::Decode("YQ==", 4, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); - - result_buffer[1] = 'b'; - status = base64::Decode("YWI=", 4, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); - - result_buffer[2] = 'c'; - status = base64::Decode("YWJj", 4, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); - - result_buffer[3] = 'd'; - status = base64::Decode("YWJjZA==", 8, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); - - result_buffer[4] = 'e'; - status = base64::Decode("YWJjZGU=", 8, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); -} - -TEST_F(Base64Test, DecodeInputError) { - unsigned char buffer[10]; - base64::DecodeStatus status = base64::kSuccess; - status = base64::Decode("Y@==", 4, buffer, 10); - EXPECT_EQ(base64::kBadCharError, status); - - status = base64::Decode("Y Q==", 4, buffer, 10); - EXPECT_EQ(base64::kSuccess, status); - - status = base64::Decode("Y", 1, buffer, 10); - EXPECT_EQ(base64::kPadError, status); -} - -TEST_F(Base64Test, DecodeOverflowError) { - unsigned char buffer[10]; - base64::DecodeStatus status = base64::kSuccess; - status = base64::Decode("YWJjZA==", 8, buffer, 3); - EXPECT_EQ(base64::kOutputOverflowError, status); - - status = base64::Decode("YWJjZA==", 8, buffer, 4); - EXPECT_EQ(base64::kSuccess, status); - - status = base64::Decode("YQ==", 8, buffer, 0); - EXPECT_EQ(base64::kOutputOverflowError, status); - - status = base64::Decode("YQ==", 8, buffer, 1); - EXPECT_EQ(base64::kSuccess, status); -} - -} // namespace o3d - - diff --git a/o3d/utils/cross/dataurl.cc b/o3d/utils/cross/dataurl.cc deleted file mode 100644 index 328d174..0000000 --- a/o3d/utils/cross/dataurl.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// This file contains the definition of functions for dealing with data urls. - -#include "utils/cross/dataurl.h" -#include "core/cross/types.h" -#include "utils/cross/base64.h" - -namespace o3d { -namespace dataurl { - -const char* const kEmptyDataURL = "data:,"; - -String ToDataURL(const String& mime_type, const void* data, size_t length) { - String header(String("data:") + mime_type + ";base64,"); - String result(header.size() + base64::GetEncodeLength(length), ' '); - result.replace(0, header.size(), header); - base64::Encode(data, length, &result[header.size()]); - return result; -} - -// Decodes the data URL and stores a pointer to the data in dst_buffer -bool FromDataURL(const String& data_url, - scoped_array<uint8>* dst_buffer, - size_t* output_length, - String* error_string) { - // First parse the data_url - const String kDataHeader("data:"); - const String kBase64Header(";base64,"); - // The string has to be long enough. - if (data_url.size() <= kDataHeader.size() + kBase64Header.size()) { - *error_string = "Invalid formatting: The data URL is not long enough."; - return false; - } - // it must start with "data:" - if (data_url.compare(0, kDataHeader.size(), kDataHeader) != 0) { - *error_string - = "Invalid formatting: The data URL must start with 'data:'"; - return false; - } - // we only support base64 data URL's - String::size_type data_index = data_url.find(kBase64Header); - if (data_index == String::npos) { - *error_string - = "Invalid formatting: The data URL have ';base64,' in the header."; - return false; - } - // The start of the data. - data_index += kBase64Header.size(); - if (data_index >= data_url.size()) { - *error_string - = "Invalid formatting: There must be data in the body of the data URL."; - return false; - } - - // Get the length of the decoded data - size_t input_length = data_url.size() - data_index; - base64::DecodeStatus return_code = base64::GetDecodeLength( - &data_url[data_index], - input_length, - output_length); - if (return_code != base64::kSuccess) { - if (return_code == base64::kPadError) { - *error_string - = "Invalid formatting: Padding error in the data URL data."; - } else { - *error_string - = "Invalid formatting: Bad character error in the data URL data."; - } - return false; - } - - dst_buffer->reset(new uint8[*output_length]); - base64::Decode(&data_url[data_index], - input_length, - dst_buffer->get(), - (*output_length)); - - return true; -} - -} // namespace dataurl -} // namespace o3d - diff --git a/o3d/utils/cross/dataurl.h b/o3d/utils/cross/dataurl.h deleted file mode 100644 index c403388..0000000 --- a/o3d/utils/cross/dataurl.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// This file contains the declaration of functions for dealing with data urls. - -#ifndef O3D_UTILS_CROSS_DATAURL_H_ -#define O3D_UTILS_CROSS_DATAURL_H_ - -#include "core/cross/types.h" -#include "base/scoped_ptr.h" - -namespace o3d { -namespace dataurl { - -// An empty data URL. ("data:,") -extern const char* const kEmptyDataURL; - -// Creates a data URL for the given data. -String ToDataURL(const String& mime_type, const void* data, size_t length); - -// Decodes the data from a data URL and stores a pointer to the data in -// dst_buffer. If an error occurs in decoding, it returns false and -// error_string will contain an error message. Otherwise, returns true. -// Parameters: -// data_url: The data URL from which to extract the data. -// dst_buffer: A pointer to the output data will be stored in this -// scoped_array. -// output_length: The length of the output data will be stored at this -// address. -// error_string: This will contain the error message, if an error occurs. -// Returns: -// False if an error occurs in decoding, true otherwise. -bool FromDataURL(const String& data_url, - scoped_array<uint8>* dst_buffer, - size_t* output_length, - String* error_string); - -} // namespace dataurl -} // namespace o3d - -#endif // O3D_UTILS_CROSS_DATAURL_H_ - diff --git a/o3d/utils/cross/dataurl_test.cc b/o3d/utils/cross/dataurl_test.cc deleted file mode 100644 index f189011..0000000 --- a/o3d/utils/cross/dataurl_test.cc +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of dataurl functions - -#include "tests/common/win/testing_common.h" -#include "utils/cross/dataurl.h" - -namespace o3d { - -class DataURLTest : public testing::Test { -}; - -TEST_F(DataURLTest, kEmptyDataURL) { - EXPECT_STREQ("data:,", dataurl::kEmptyDataURL); -} - -TEST_F(DataURLTest, ToDataURL) { - EXPECT_STREQ("data:a/b;base64,YWJj", - dataurl::ToDataURL("a/b", "abc", 3).c_str()); - EXPECT_STREQ("data:de/ej;base64,YWIAYw==", - dataurl::ToDataURL("de/ej", "ab\0c", 4).c_str()); -} - -TEST_F(DataURLTest, FromDataURL) { - String data_url("data:a/b;base64,YWJj"); - scoped_array<uint8> output; - size_t output_length; - String error_string; - - EXPECT_TRUE(dataurl::FromDataURL(data_url, - &output, - &output_length, - &error_string)); - EXPECT_EQ(3u, output_length); - EXPECT_EQ(0, memcmp("abc", output.get(), 3)); -} - -TEST_F(DataURLTest, FromDataURLFormatErrors) { - scoped_array<uint8> output; - size_t output_length; - String error_string(""); - // Not long enough - EXPECT_FALSE(dataurl::FromDataURL("", - &output, - &output_length, - &error_string)); - EXPECT_LT(0u, error_string.size()); - // Does not start with "data:" - error_string = ""; - EXPECT_FALSE(dataurl::FromDataURL("aaaaaaaaaaaaaaaa", - &output, - &output_length, - &error_string)); - EXPECT_LT(0u, error_string.size()); - // Must contain base64 - error_string = ""; - EXPECT_FALSE(dataurl::FromDataURL("data:aaaaaaaaaaa", - &output, - &output_length, - &error_string)); - EXPECT_LT(0u, error_string.size()); - // Must contain data. - error_string = ""; - EXPECT_FALSE(dataurl::FromDataURL("data:aa;base64,", - &output, - &output_length, - &error_string)); - EXPECT_LT(0u, error_string.size()); - - // Bad character in data. - error_string = ""; - EXPECT_FALSE(dataurl::FromDataURL("data:;base64,@", - &output, - &output_length, - &error_string)); - EXPECT_LT(0u, error_string.size()); - // Padding error in data. - error_string = ""; - EXPECT_FALSE(dataurl::FromDataURL("data:;base64,Y", - &output, - &output_length, - &error_string)); - EXPECT_LT(0u, error_string.size()); - // Correct. - error_string = ""; - EXPECT_TRUE(dataurl::FromDataURL("data:;base64,YWJj", - &output, - &output_length, - &error_string)); - EXPECT_EQ(0u, error_string.size()); -} - -} // namespace o3d - - diff --git a/o3d/utils/cross/file_path_utils.cc b/o3d/utils/cross/file_path_utils.cc deleted file mode 100644 index 06b7015..0000000 --- a/o3d/utils/cross/file_path_utils.cc +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definitions for some convenience functions -// used to make FilePaths more useful. - -#include "utils/cross/file_path_utils.h" -#include "base/file_util.h" -#include "base/file_path.h" -#include "base/utf_string_conversions.h" - -namespace o3d { -std::wstring FilePathToWide(const FilePath& input) { -#if defined(OS_WIN) - return input.value(); -#else - return UTF8ToWide(input.value()); -#endif -} - -FilePath WideToFilePath(const std::wstring& input) { -#if defined(OS_WIN) - return FilePath(input); -#else - return FilePath(WideToUTF8(input)); -#endif -} - -String FilePathToUTF8(const FilePath& input) { -#if defined(OS_WIN) - return WideToUTF8(input.value()); -#else - return input.value(); -#endif -} - -FilePath UTF8ToFilePath(const String& input) { -#if defined(OS_WIN) - return FilePath(UTF8ToWide(input)); -#else - return FilePath(input); -#endif -} - -FilePath::StringType UTF8ToFilePathStringType(const String& input) { -#if defined(OS_WIN) - return UTF8ToWide(input); -#else - return input; -#endif -} - -bool AbsolutePath(FilePath* absolute_path) { -#if defined(OS_WIN) - return file_util::AbsolutePath(absolute_path); -#else - // On the Posix implementation of file_util::AbsolutePath, - // realpath() is used, which only works if the path actually exists. - // So, we try using AbsolutePath, and if it doesn't work, we fake it - // by just prepending the current working direcory if it's not - // already absolute. - if (absolute_path->IsAbsolute()) { - return true; - } else { - FilePath new_absolute_path = FilePath(*absolute_path); - if (file_util::AbsolutePath(&new_absolute_path)) { - *absolute_path = new_absolute_path; - return true; - } else { - // OK, so we failed to make an absolute path above, and we know - // it's not an absolute path to begin with, so we just prepend - // the current working directory. - FilePath cwd_path; - if (!file_util::GetCurrentDirectory(&cwd_path)) { - return false; - } - *absolute_path = cwd_path.Append(*absolute_path); - return true; - } - } -#endif -} - -bool GetRelativePathIfPossible(const FilePath& base_dir, - const FilePath& candidate, - FilePath *result) { - FilePath parent = FilePath(base_dir.StripTrailingSeparators()); - FilePath child = FilePath(candidate.StripTrailingSeparators()); - - // If we can't convert the child to an absolute path for some - // reason, then we just do nothing and return the candidate. - if (!child.IsAbsolute() && !AbsolutePath(&child)) { - *result = candidate; - return false; - } - - // If we can't convert the parent to an absolute path for some - // reason, then we just do nothing and return the absolute path to - // the child. - if (!parent.IsAbsolute() && !AbsolutePath(&parent)) { - *result = child; - return false; - } - - FilePath::StringType child_str = child.value(); - FilePath::StringType parent_str = parent.value(); - - // If the child is too short, it can't be a child of parent, and if - // it doesn't have a separator in the right place, then it also - // can't be a child, so we return the absolute path to the child. - // file_util::AbsolutePath() normalizes '/' to '\' on Windows, so we - // only need to check kSeparators[0]. - if (child_str.length() <= parent_str.length() || - child_str[parent_str.length()] != FilePath::kSeparators[0]) { - *result = child; - return false; - } - - if ( -#if defined(OS_WIN) - // file_util::AbsolutePath() does not flatten case on Windows, - // so we must do a case-insensitive compare. - StartsWith(child_str, parent_str, false) -#else - StartsWithASCII(child_str, parent_str, true) -#endif - ) { - // Add one to skip over the dir separator. - child_str = child_str.substr(parent_str.size() + 1); - - // Now we know we can return the relative path. - *result = FilePath(child_str); - return true; - } else { - *result = FilePath(child_str); - return false; - } -} - -namespace { // anonymous namespace. - -// Tries to find a file path_to_find in path_to_search. Will start with -// base name and progressively try each higher path. Example: -// -// FindFile('this/that', 'foo/bar/baf.txt'); -// -// Looks for: -// this/that/foo/bar/baf.txt -// this/that/bar/baf.txt -// this/that/baf.txt -bool FindFileHelper(const FilePath& path_to_search, - const FilePath& path_to_find, - FilePath* found_path) { - std::vector<FilePath::StringType> parts; - path_to_find.GetComponents(&parts); - - for (size_t ii = 0; ii < parts.size(); ++ii) { - // build a path from parts. - FilePath path(path_to_search); - for (size_t jj = ii; jj < parts.size(); ++jj) { - path = path.Append(parts[jj]); - } - if (file_util::PathExists(path)) { - *found_path = path; - return true; - } - } - - return false; -} - -} // anonymous namespace - -bool FindFile(const std::vector<FilePath>& paths_to_search, - const FilePath& path_to_find, - FilePath* found_path) { - if (file_util::PathExists(path_to_find)) { - *found_path = path_to_find; - return true; - } - - for (size_t ii = 0; ii < paths_to_search.size(); ++ii) { - FilePath absolute_path(paths_to_search[ii]); - o3d::AbsolutePath(&absolute_path); - - if (FindFileHelper(absolute_path, path_to_find, found_path)) { - return true; - } - } - return false; -} - -} // end namespace o3d diff --git a/o3d/utils/cross/file_path_utils.h b/o3d/utils/cross/file_path_utils.h deleted file mode 100644 index 463b47de..0000000 --- a/o3d/utils/cross/file_path_utils.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration for some convenience functions -// used to make FilePaths more useful. - -#ifndef O3D_UTILS_CROSS_FILE_PATH_UTILS_H_ -#define O3D_UTILS_CROSS_FILE_PATH_UTILS_H_ - -#include <string> -#include <vector> -#include "base/file_path.h" -#include "core/cross/types.h" - -namespace o3d { -// TODO: Go through the process to add these to FilePath -// itself in the Chromium depot. - -std::wstring FilePathToWide(const FilePath& input); -FilePath WideToFilePath(const std::wstring& input); -String FilePathToUTF8(const FilePath& input); -FilePath UTF8ToFilePath(const String& input); -FilePath::StringType UTF8ToFilePathStringType(const String& input); - -// On Windows, this is just the same as file_util::AbsolutePath. -// On the Posix implementation of file_util::AbsolutePath, -// realpath() is used, which only works if the path actually exists. -// So, we try using AbsolutePath, and if it doesn't work, we fake it -// by just prepending the cwd if it's not already an absolute path. -bool AbsolutePath(FilePath* abs_path); - -// If the candidate is a child (a file or directory in a subdir of the -// base directory or the base directory itself), then we figure out -// the relative path to it. If not, then we just return the absolute -// path to the candidate. Does not return any paths that would -// require use of ".." to form a relative path. Returns true if the -// path returned in "result" is a relative path. -bool GetRelativePathIfPossible(const FilePath& base_dir, - const FilePath& candidate, - FilePath *result); - -// Tries to find a file path_to_find in paths_to_search. Will start with -// base name and progressively try each higher path. Example: -// -// FindFile(['this/that', 'there'], 'foo/bar/baf.txt'); -// -// Looks for: -// foo/bar/baf.txt -// this/that/foo/bar/baf.txt -// this/that/bar/baf.txt -// this/that/baf.txt -// there/foo/bar/baf.txt -// there/bar/baf.txt -// there/baf.txt -bool FindFile(const std::vector<FilePath>& paths_to_search, - const FilePath& path_to_find, - FilePath* found_path); - -} // namespace o3d - -#endif // O3D_UTILS_CROSS_FILE_PATH_UTILS_H_ diff --git a/o3d/utils/cross/file_path_utils_test.cc b/o3d/utils/cross/file_path_utils_test.cc deleted file mode 100644 index ac4d777..0000000 --- a/o3d/utils/cross/file_path_utils_test.cc +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of the file path utils. -#include <stdio.h> - -#include "base/file_path.h" -#include "base/file_util.h" -#include "tests/common/win/testing_common.h" -#include "utils/cross/file_path_utils.h" - -namespace o3d { - -namespace { // anonymous namespace - -bool FilePathsEqual(const FilePath& path_1, const FilePath path_2) { - const FilePath::StringType& p1(path_1.value()); - const FilePath::StringType& p2(path_2.value()); - if (p1.size() == p2.size()) { - for (size_t ii = 0; ii < p1.size(); ++ii) { - if (p1[ii] != p2[ii]) { - if (!FilePath::IsSeparator(p1[ii]) || !FilePath::IsSeparator(p2[ii])) { - return false; - } - } - } - return true; - } - return false; -} - -} // anonymous namespace - -class FilePathUtilsTest : public testing::Test { -}; - -TEST_F(FilePathUtilsTest, ConvertFilePathToUTF8) { - std::string test_path("/this/is/a/path"); - FilePath source_path(FILE_PATH_LITERAL("/this/is/a/path")); - EXPECT_EQ(test_path, FilePathToUTF8(source_path)); -} - -TEST_F(FilePathUtilsTest, ConvertFilePathToWide) { - std::wstring test_path(L"/this/is/a/path"); - FilePath source_path(FILE_PATH_LITERAL("/this/is/a/path")); - EXPECT_EQ(test_path, FilePathToWide(source_path)); -} - -TEST_F(FilePathUtilsTest, ConvertWideToFilePath) { - std::wstring test_path(L"/this/is/a/path"); - FilePath dest_path = WideToFilePath(test_path); - EXPECT_STREQ(FILE_PATH_LITERAL("/this/is/a/path"), dest_path.value().c_str()); -} - -TEST_F(FilePathUtilsTest, ConvertUTF8ToFilePath) { - std::string test_path("/this/is/a/path"); - FilePath dest_path = UTF8ToFilePath(test_path); - EXPECT_STREQ(FILE_PATH_LITERAL("/this/is/a/path"), dest_path.value().c_str()); -} - -TEST_F(FilePathUtilsTest, AbsolutePathBasic) { - FilePath cwd; - file_util::GetCurrentDirectory(&cwd); -#if defined(OS_WIN) - FilePath test_path(FILE_PATH_LITERAL("this\\is\\a\\path")); -#else - FilePath test_path(FILE_PATH_LITERAL("this/is/a/path")); -#endif - FilePath abs_path = test_path; - AbsolutePath(&abs_path); - FilePath expected_result = cwd; - expected_result = expected_result.Append(test_path); - EXPECT_STREQ(expected_result.value().c_str(), abs_path.value().c_str()); -} - -TEST_F(FilePathUtilsTest, AbsolutePathAlreadyAbsolute) { -#if defined(OS_WIN) - FilePath test_path(FILE_PATH_LITERAL("c:\\this\\is\\a\\path")); -#else - FilePath test_path(FILE_PATH_LITERAL("/this/is/a/path")); -#endif - FilePath abs_path = test_path; - AbsolutePath(&abs_path); - EXPECT_STREQ(test_path.value().c_str(), abs_path.value().c_str()); -} - -#if defined(OS_WIN) -TEST_F(FilePathUtilsTest, AbsolutePathAlreadyAbsoluteWindowsUnc) { - FilePath test_path(FILE_PATH_LITERAL("\\\\this\\is\\a\\path")); - FilePath abs_path = test_path; - bool result = AbsolutePath(&abs_path); - EXPECT_STREQ(test_path.value().c_str(), abs_path.value().c_str()); -} -#endif - -TEST_F(FilePathUtilsTest, RelativePathsBasic) { -#if defined(OS_WIN) - FilePath expected_result(FILE_PATH_LITERAL("under\\parent")); -#else - FilePath expected_result(FILE_PATH_LITERAL("under/parent")); -#endif - FilePath base_path(FILE_PATH_LITERAL("/this/is/a/path")); - FilePath child_path(FILE_PATH_LITERAL("/this/is/a/path/under/parent")); - FilePath result; - bool is_relative = GetRelativePathIfPossible(base_path, child_path, &result); - EXPECT_STREQ(expected_result.value().c_str(), result.value().c_str()); - EXPECT_TRUE(is_relative); -} - -#if defined(OS_WIN) -TEST_F(FilePathUtilsTest, RelativePathsWindowsAbsolute) { - FilePath expected_result(FILE_PATH_LITERAL("under\\parent")); - FilePath base_path(FILE_PATH_LITERAL("c:\\this\\is\\a\\path")); - FilePath child_path( - FILE_PATH_LITERAL("c:\\this\\is\\a\\path\\under\\parent")); - FilePath result; - bool is_relative = GetRelativePathIfPossible(base_path, child_path, &result); - EXPECT_STREQ(expected_result.value().c_str(), result.value().c_str()); - EXPECT_TRUE(is_relative); -} - -TEST_F(FilePathUtilsTest, RelativePathsWindowsDifferentDrives) { - FilePath base_path(FILE_PATH_LITERAL("c:\\this\\is\\a\\path")); - FilePath child_path( - FILE_PATH_LITERAL("d:\\this\\is\\a\\path\\not\\under\\parent")); - FilePath result; - bool is_relative = GetRelativePathIfPossible(base_path, child_path, &result); - EXPECT_STREQ(child_path.value().c_str(), result.value().c_str()); - EXPECT_FALSE(is_relative); -} -#endif - -TEST_F(FilePathUtilsTest, RelativePathsCaseDifferent) { - FilePath base_path(FILE_PATH_LITERAL("/This/Is/A/Path")); - FilePath child_path(FILE_PATH_LITERAL("/this/is/a/path/under/parent")); - FilePath result; - bool is_relative = GetRelativePathIfPossible(base_path, child_path, &result); -#if defined(OS_WIN) - EXPECT_STREQ(FILE_PATH_LITERAL("under\\parent"), result.value().c_str()); - EXPECT_TRUE(is_relative); -#else - EXPECT_STREQ(child_path.value().c_str(), result.value().c_str()); - EXPECT_FALSE(is_relative); -#endif -} - -TEST_F(FilePathUtilsTest, RelativePathsTrailingSlash) { -#if defined(OS_WIN) - FilePath expected_result(FILE_PATH_LITERAL("under\\parent")); -#else - FilePath expected_result(FILE_PATH_LITERAL("under/parent")); -#endif - FilePath base_path(FILE_PATH_LITERAL("/this/is/a/path/")); - FilePath child_path(FILE_PATH_LITERAL("/this/is/a/path/under/parent")); - FilePath result; - bool is_relative = GetRelativePathIfPossible(base_path, child_path, &result); - EXPECT_STREQ(expected_result.value().c_str(), result.value().c_str()); - EXPECT_TRUE(is_relative); -} - -TEST_F(FilePathUtilsTest, RelativePathsRelativeInputs) { -#if defined(OS_WIN) - FilePath expected_result(FILE_PATH_LITERAL("under\\parent")); -#else - FilePath expected_result(FILE_PATH_LITERAL("under/parent")); -#endif - FilePath base_path(FILE_PATH_LITERAL("this/is/a/path")); - FilePath child_path(FILE_PATH_LITERAL("this/is/a/path/under/parent")); - FilePath result; - bool is_relative = GetRelativePathIfPossible(base_path, child_path, &result); - EXPECT_STREQ(expected_result.value().c_str(), result.value().c_str()); - EXPECT_TRUE(is_relative); -} - -TEST_F(FilePathUtilsTest, FindFile) { - String folder_name_1(*g_program_path + "/unittest_data"); - String folder_name_2(*g_program_path + "/bitmap_test"); - FilePath folder_path_1 = UTF8ToFilePath(folder_name_1); - FilePath folder_path_2 = UTF8ToFilePath(folder_name_2); - String file_name_1("fur.fx"); - String file_name_2("someplace/somewhere/tga-256x256-32bit.tga"); - FilePath file_path_1 = UTF8ToFilePath(file_name_1); - FilePath file_path_2 = UTF8ToFilePath(file_name_2); - FilePath out_path; - - FilePath expected_path_1(folder_path_1); - expected_path_1 = expected_path_1.Append(file_path_1); - o3d::AbsolutePath(&expected_path_1); - FilePath expected_path_2(folder_path_2); - expected_path_2 = - expected_path_2.Append(UTF8ToFilePath("tga-256x256-32bit.tga")); - o3d::AbsolutePath(&expected_path_2); - - std::vector<FilePath> paths; - EXPECT_FALSE(FindFile(paths, file_path_1, &out_path)); - EXPECT_FALSE(FindFile(paths, file_path_2, &out_path)); - paths.push_back(folder_path_1); - EXPECT_TRUE(FindFile(paths, file_path_1, &out_path)); - EXPECT_FALSE(FindFile(paths, file_path_2, &out_path)); - EXPECT_TRUE(FilePathsEqual(out_path, expected_path_1)); - paths.push_back(folder_path_2); - EXPECT_TRUE(FindFile(paths, file_path_1, &out_path)); - EXPECT_TRUE(FilePathsEqual(out_path, expected_path_1)); - EXPECT_TRUE(FindFile(paths, file_path_2, &out_path)); - EXPECT_TRUE(FilePathsEqual(out_path, expected_path_2)); -} - -} // namespace o3d diff --git a/o3d/utils/cross/file_text_reader.cc b/o3d/utils/cross/file_text_reader.cc deleted file mode 100644 index 314be5e..0000000 --- a/o3d/utils/cross/file_text_reader.cc +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class FileTextReader. The -// tests are in string_reader_test.cc. - -#include "utils/cross/file_text_reader.h" - -#include <stdio.h> -#include <sys/stat.h> -#include "base/logging.h" -#include "base/scoped_ptr.h" - -namespace o3d { - -FileTextReader::FileTextReader(FILE* input) - : TextReader(), input_(input) { - if (input_ == NULL) { - LOG(FATAL) << "Invalid NULL file pointer"; - } - if (::ferror(input_) != 0) { - DLOG(FATAL) << "Invalid file pointer."; - } -} - -FileTextReader::~FileTextReader() { -} - -size_t FileTextReader::position() const { - if (input_) { - return ::ftell(input_); - } else { - return 0; - } -} - -bool FileTextReader::IsAtEnd() const { - size_t position = ::ftell(input_); - if (::feof(input_) != 0) { - return true; - } - return GetFileSize() == position; -} - -std::string FileTextReader::PeekString(std::string::size_type count) const { - if (IsAtEnd()) { - return std::string(""); - } - - // Find out where we are in the stream. - size_t original_pos = ::ftell(input_); - - // We're just re-using code here -- the stream will not be affected - // because we will seek back to where we started. - std::string result = const_cast<FileTextReader*>(this)->ReadString(count); - - // Go back to where we started in the stream. - ::fseek(input_, original_pos, SEEK_SET); - return result; -} - -char FileTextReader::ReadChar() { - if (!IsAtEnd()) { - return ::fgetc(input_); - } else { - return 0; - } -} - -std::string FileTextReader::ReadString(std::string::size_type count) { - if (count <= 0 || IsAtEnd()) { - return std::string(""); - } - - // Allocate a string to hold the data. - scoped_array<char> buffer(new char[count + 1]); - - // Read it. - size_t count_read = ::fread(reinterpret_cast<void*>(buffer.get()), - sizeof(char), - count, - input_); - - // Make sure it's null terminated. - (buffer.get())[count_read] = 0; - return std::string(buffer.get()); -} - -std::string FileTextReader::ReadLine() { - // Find out where we are in the stream. - int original_pos = ::ftell(input_); - - // Find the occurance of the next eol character, regardless of what - // kind of terminator it is. - static const char linefeed = '\n'; - static const char carriage_return = '\r'; - int eol_pos = -1; - int eol_len = 1; - while (!IsAtEnd()) { - char eol = ::fgetc(input_); - if (eol == linefeed) { - eol_pos = ::ftell(input_); - break; - } - if (eol == carriage_return) { - eol_pos = ::ftell(input_); - if (IsAtEnd()) { - break; - } - eol = ::fgetc(input_); - if (eol == linefeed) { - eol_len = 2; - } - break; - } - } - - // Go back to where we started in the stream. - ::fseek(input_, original_pos, SEEK_SET); - - if (eol_pos > 0) { - int count = eol_pos - original_pos - 1; - std::string result = ReadString(count); - // Strip off one EOL marker (of the appropriate length). - ReadString(eol_len); - return result; - } else { - // If there are no end of line markers in this file, just send - // back the whole file. - return ReadToEnd(); - } -} - -std::string FileTextReader::ReadToEnd() { - size_t remaining_size = GetRemainingSize(); - if (remaining_size > 0) { - return ReadString(remaining_size); - } else { - return std::string(""); - } -} - -size_t FileTextReader::GetFileSize() const { - struct stat file_info; -#if defined(OS_WIN) - int file_number = ::_fileno(input_); -#else - int file_number = ::fileno(input_); -#endif - ::fstat(file_number, &file_info); - - return file_info.st_size; -} - -size_t FileTextReader::GetRemainingSize() const { - // Find out where we are in the stream. - int original_pos = ::ftell(input_); - - return GetFileSize() - original_pos; -} -} // end namespace o3d diff --git a/o3d/utils/cross/file_text_reader.h b/o3d/utils/cross/file_text_reader.h deleted file mode 100644 index 307679d..0000000 --- a/o3d/utils/cross/file_text_reader.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class FileTextReader. - -#ifndef O3D_UTILS_CROSS_FILE_TEXT_READER_H_ -#define O3D_UTILS_CROSS_FILE_TEXT_READER_H_ - -#include <string> -#include "utils/cross/text_reader.h" - -namespace o3d { - -// A FileTextReader reads a sequence of characters from an -// in-memory string. -class FileTextReader : public TextReader { - public: - // Prepare to read from the given input string. - explicit FileTextReader(FILE* input); - virtual ~FileTextReader(); - - virtual bool IsAtEnd() const; - virtual std::string PeekString(std::string::size_type count) const; - virtual char ReadChar(); - virtual std::string ReadString(std::string::size_type count); - virtual std::string ReadLine(); - virtual std::string ReadToEnd(); - - // Access to the original input file pointer, and the current - // position in that buffer. - const FILE* input() const { return input_; } - size_t position() const; - - protected: - size_t GetFileSize() const; - size_t GetRemainingSize() const; - - private: - FILE* input_; - DISALLOW_COPY_AND_ASSIGN(FileTextReader); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_FILE_TEXT_READER_H_ diff --git a/o3d/utils/cross/file_text_reader_test.cc b/o3d/utils/cross/file_text_reader_test.cc deleted file mode 100644 index 951e3429..0000000 --- a/o3d/utils/cross/file_text_reader_test.cc +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of class FileTextReader. -#include <stdio.h> - -#include "base/basictypes.h" -#include "tests/common/win/testing_common.h" -#include "utils/cross/file_text_reader.h" - -namespace o3d { - -namespace { -struct FileInfo { - const char* file_name_; - const char* file_contents_; -}; - -static const FileInfo kFileInfo[] = { - { "/test_file_string_one", "testing 1..2..3" }, - { "/test_file_string_two", "4..5..6" }, - { "/test_file_string_lf", "testing 1..2..3\n4..5..6\n" }, - { "/test_file_string_cr", "testing 1..2..3\r4..5..6\r" }, - { "/test_file_string_crlf", "testing 1..2..3\r\n4..5..6\r\n" }, - { "/test_file_string_lfcr", "testing 1..2..3\n\r4..5..6\n\r" }, - { "/test_file_string_lflf", "testing 1..2..3\n\n4..5..6\n\n" }, - { "/test_file_string_short", "T" }, - { "/test_file_string_empty", "" } -}; - -static const int kNumFiles = arraysize(kFileInfo); -} // end anonymous namespace - -class FileTextReaderTest : public testing::Test { - public: - FileTextReaderTest() { - test_string_one_ = kFileInfo[0].file_contents_; - test_string_two_ = kFileInfo[1].file_contents_; - test_string_lf_ = kFileInfo[2].file_contents_; - test_string_cr_ = kFileInfo[3].file_contents_; - test_string_crlf_ = kFileInfo[4].file_contents_; - test_string_lfcr_ = kFileInfo[5].file_contents_; - test_string_lflf_ = kFileInfo[6].file_contents_; - test_string_short_ = kFileInfo[7].file_contents_; - test_string_empty_ = kFileInfo[8].file_contents_; - } - virtual void SetUp() { - // This clears out the existing Temporary files and rewrites them. - std::string tmp_base(g_program_path->data()); - for (int i = 0; i < kNumFiles; i++) { - std::string filename = tmp_base + kFileInfo[i].file_name_; - FILE* file_pointer = fopen(filename.c_str(), "wb+"); - int contents_size = ::strlen(kFileInfo[i].file_contents_); - if (contents_size > 0) { - ::fwrite(kFileInfo[i].file_contents_, sizeof(char), contents_size, - file_pointer); - ::fseek(file_pointer, 0, SEEK_SET); - } - file_pointers_[i] = file_pointer; - } - } - virtual void TearDown() { - std::string tmp_base(g_program_path->data()); - // Clear out the tmp files. - for (int i = 0; i < kNumFiles; i++) { - if (file_pointers_[i]) { - ::fclose(file_pointers_[i]); - } - std::string path = tmp_base + kFileInfo[i].file_name_; -#if defined(OS_WIN) - ::_unlink(path.c_str()); -#else - ::unlink(path.c_str()); -#endif - file_pointers_[i] = NULL; - } - } - - FILE* file_pointers_[kNumFiles]; - std::string test_string_one_; - std::string test_string_two_; - std::string test_string_lf_; - std::string test_string_cr_; - std::string test_string_crlf_; - std::string test_string_lfcr_; - std::string test_string_lflf_; - std::string test_string_short_; - std::string test_string_empty_; -}; - -TEST_F(FileTextReaderTest, StartAtBeginning) { - FileTextReader reader(file_pointers_[0]); - EXPECT_EQ(0U, reader.position()); - EXPECT_EQ(file_pointers_[0], reader.input()); - EXPECT_FALSE(reader.IsAtEnd()); -} - -TEST_F(FileTextReaderTest, TestPeekString) { - FileTextReader reader(file_pointers_[0]); - EXPECT_EQ(test_string_one_.substr(0, 6), reader.PeekString(6)); - EXPECT_EQ(0U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); -} - -TEST_F(FileTextReaderTest, ReadsSingleCharacter) { - FileTextReader reader(file_pointers_[0]); - EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); - EXPECT_EQ(1U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_one_.substr(1, 2), reader.PeekString(2)); - EXPECT_EQ(1U, reader.position()); -} - -TEST_F(FileTextReaderTest, ReadsMultipleCharacters) { - FileTextReader reader(file_pointers_[0]); - EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); - EXPECT_EQ(test_string_one_.substr(1, 1)[0], reader.ReadChar()); - EXPECT_EQ(2U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_one_.substr(2, 2), reader.PeekString(2)); - EXPECT_EQ(2U, reader.position()); -} - -TEST_F(FileTextReaderTest, ReadsFile) { - FileTextReader reader(file_pointers_[0]); - EXPECT_EQ(test_string_one_.substr(0, 7), reader.ReadString(7)); - EXPECT_EQ(7U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_one_.substr(7, 2), reader.PeekString(2)); - EXPECT_EQ(7U, reader.position()); -} - -TEST_F(FileTextReaderTest, EmptyFile) { - FileTextReader reader(file_pointers_[8]); - EXPECT_EQ("", reader.PeekString(1)); - EXPECT_EQ(0U, reader.position()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(0, reader.ReadChar()); - EXPECT_TRUE(reader.IsAtEnd()); -} - -TEST_F(FileTextReaderTest, TinyFile) { - FileTextReader reader(file_pointers_[7]); - EXPECT_EQ(test_string_short_.substr(0, 1), reader.PeekString(1)); - EXPECT_EQ(0U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_short_[0], reader.ReadChar()); - EXPECT_TRUE(reader.IsAtEnd()); -} - -TEST_F(FileTextReaderTest, ReadsToEnd) { - FileTextReader reader(file_pointers_[2]); - EXPECT_EQ(test_string_lf_, reader.ReadToEnd()); - EXPECT_EQ(test_string_lf_.size(), reader.position()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ("", reader.ReadString(1)); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lf_.size(), reader.position()); -} - - -TEST_F(FileTextReaderTest, ReadsLinefeedFile) { - FileTextReader reader(file_pointers_[2]); - std::string line = reader.ReadLine(); - EXPECT_EQ(test_string_one_, line); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lf_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lf_.size(), reader.position()); -} - -TEST_F(FileTextReaderTest, ReadsCarriageReturnFile) { - FileTextReader reader(file_pointers_[3]); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_cr_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_cr_.size(), reader.position()); -} - - -TEST_F(FileTextReaderTest, ReadsCarriageReturnLinefeedFile) { - FileTextReader reader(file_pointers_[4]); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 2, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_crlf_.substr(test_string_one_.size() + 2, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 2, reader.position()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_crlf_.size(), reader.position()); -} - -TEST_F(FileTextReaderTest, ReadsLinefeedCarriageReturnFile) { - FileTextReader reader(file_pointers_[5]); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lfcr_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lfcr_.size(), reader.position()); -} - -TEST_F(FileTextReaderTest, ReadsLinefeedLinefeedFile) { - FileTextReader reader(file_pointers_[6]); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lflf_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lflf_.size(), reader.position()); -} - -} // namespace o3d diff --git a/o3d/utils/cross/file_text_writer.cc b/o3d/utils/cross/file_text_writer.cc deleted file mode 100644 index ed83133..0000000 --- a/o3d/utils/cross/file_text_writer.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class FileTextWriter. - -#include "utils/cross/file_text_writer.h" -#include "base/logging.h" - -namespace o3d { -FileTextWriter::FileTextWriter(FILE* file, - Encoding encoding, - NewLine new_line) - : TextWriter(new_line), - file_(file), - encoding_(encoding) { - DCHECK(file_); -} - -FileTextWriter::~FileTextWriter() { - Close(); -} - -void FileTextWriter::WriteChar(char c) { - DCHECK(file_); - fputc(c, file_); -} - -void FileTextWriter::WriteString(const std::string& s) { - DCHECK(file_); - if (s.length() != fwrite(s.c_str(), 1, s.length(), file_)) { - return; - } -} - -void FileTextWriter::Close() { - if (file_ != NULL) { - fclose(file_); - file_ = NULL; - } -} -} // namespace o3d diff --git a/o3d/utils/cross/file_text_writer.h b/o3d/utils/cross/file_text_writer.h deleted file mode 100644 index 7776e47..0000000 --- a/o3d/utils/cross/file_text_writer.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class FileTextWriter. - -#ifndef O3D_UTILS_CROSS_FILE_TEXT_WRITER_H_ -#define O3D_UTILS_CROSS_FILE_TEXT_WRITER_H_ - -#include <stdio.h> - -#include <string> - -#include "utils/cross/text_writer.h" - -namespace o3d { - -// A FileTextWriter writes a sequence of characters to a file. -class FileTextWriter : public TextWriter { - public: - // TODO: decide how we're going to use Unicode: wstrings of wide - // chars or strings encoded as UTF8? Only support ASCII for now (although it - // doesn't check that all chars are in the ASCII range). - enum Encoding { - ASCII, - }; - - // Take ownership of the given file. Prepare to write characters to - // it using the specified character encoding and new line sequence. - FileTextWriter(FILE* file, Encoding encoding, NewLine new_line); - virtual ~FileTextWriter(); - virtual void WriteChar(char c); - virtual void WriteString(const std::string& s); - virtual void Close(); - private: - FILE* file_; - Encoding encoding_; - DISALLOW_COPY_AND_ASSIGN(FileTextWriter); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_FILE_TEXT_WRITER_H_ diff --git a/o3d/utils/cross/json_writer.cc b/o3d/utils/cross/json_writer.cc deleted file mode 100644 index a49700e..0000000 --- a/o3d/utils/cross/json_writer.cc +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class JsonWriter. - -#include "utils/cross/json_writer.h" -#include "base/logging.h" -#include "base/string_util.h" - -using std::string; - -namespace o3d { -JsonWriter::JsonWriter(TextWriter* writer, int indent_spaces) - : writer_(writer), - indent_spaces_(indent_spaces), - compacting_level_(0), - current_indentation_(0), - new_line_pending_(false), - comma_pending_(false) { - DCHECK(writer_); -} - -JsonWriter::~JsonWriter() { - Close(); -} - -void JsonWriter::OpenObject() { - DCHECK(writer_); - WritePending(); - writer_->WriteChar('{'); - IncreaseIndentation(); - ScheduleNewLine(); -} - -void JsonWriter::CloseObject() { - DCHECK(writer_); - CancelComma(); - DecreaseIndentation(); - WritePending(); - writer_->WriteChar('}'); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::OpenArray() { - DCHECK(writer_); - WritePending(); - writer_->WriteChar('['); - IncreaseIndentation(); - ScheduleNewLine(); -} - -void JsonWriter::CloseArray() { - DCHECK(writer_); - CancelComma(); - DecreaseIndentation(); - WritePending(); - writer_->WriteChar(']'); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::BeginCompacting() { - WritePending(); - ++compacting_level_; -} - -void JsonWriter::EndCompacting() { - DCHECK_GT(compacting_level_, 0); - --compacting_level_; -} - -void JsonWriter::WritePropertyName(const string& name) { - DCHECK(writer_); - WritePending(); - writer_->WriteChar('\"'); - WriteEscapedString(name); - writer_->WriteChar('\"'); - if (compacting_level_ > 0) { - writer_->WriteChar(':'); - } else { - writer_->WriteString(string(": ")); - } -} - -void JsonWriter::WriteBool(bool value) { - DCHECK(writer_); - WritePending(); - writer_->WriteBool(value); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::WriteInt(int value) { - DCHECK(writer_); - WritePending(); - writer_->WriteInt(value); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::WriteUnsignedInt(unsigned int value) { - DCHECK(writer_); - WritePending(); - writer_->WriteUnsignedInt(value); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::WriteFloat(float value) { - DCHECK(writer_); - WritePending(); - writer_->WriteFloat(value); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::WriteString(const string& value) { - DCHECK(writer_); - WritePending(); - writer_->WriteChar('\"'); - WriteEscapedString(value); - writer_->WriteChar('\"'); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::WriteNull() { - DCHECK(writer_); - WritePending(); - writer_->WriteString(string("null")); - ScheduleComma(); - ScheduleNewLine(); -} - -void JsonWriter::Close() { - if (writer_) { - CancelComma(); - WritePending(); - writer_->Close(); - writer_ = NULL; - } -} - -void JsonWriter::IncreaseIndentation() { - ++current_indentation_; -} - -void JsonWriter::DecreaseIndentation() { - DCHECK_GT(current_indentation_, 0); - --current_indentation_; -} - -void JsonWriter::ScheduleNewLine() { - new_line_pending_ = true; -} - -void JsonWriter::ScheduleComma() { - comma_pending_ = true; -} - -void JsonWriter::CancelComma() { - comma_pending_ = false; -} - -void JsonWriter::WritePending() { - if (comma_pending_) { - writer_->WriteChar(','); - comma_pending_ = false; - } - - if (new_line_pending_) { - if (compacting_level_ == 0) { - writer_->WriteNewLine(); - for (int i = 0; i < current_indentation_ * indent_spaces_; ++i) { - writer_->WriteChar(' '); - } - } - new_line_pending_ = false; - } -} - -void JsonWriter::WriteEscapedString(const string& unescaped) { - for (string::size_type i = 0; i < unescaped.length(); ++i) { - char c = unescaped[i]; - switch (c) { - case '\"': - writer_->WriteString("\\\""); - break; - case '\\': - writer_->WriteString("\\\\"); - break; - case '\b': - writer_->WriteString("\\b"); - break; - case '\f': - writer_->WriteString("\\f"); - break; - case '\n': - writer_->WriteString("\\n"); - break; - case '\r': - writer_->WriteString("\\r"); - break; - case '\t': - writer_->WriteString("\\t"); - break; - default: - if (c < ' ') { - writer_->WriteString(StringPrintf("\\u%04x", static_cast<int>(c))); - } else { - writer_->WriteChar(c); - } - } - } -} -} // namespace o3d diff --git a/o3d/utils/cross/json_writer.h b/o3d/utils/cross/json_writer.h deleted file mode 100644 index b9a623d..0000000 --- a/o3d/utils/cross/json_writer.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class JsonWriter. - -#ifndef O3D_UTILS_CROSS_JSON_WRITER_H_ -#define O3D_UTILS_CROSS_JSON_WRITER_H_ - -#include <string> - -#include "base/basictypes.h" -#include "utils/cross/text_writer.h" -#include "utils/cross/structured_writer.h" - -namespace o3d { - -// A JsonWriter is used to write data to a TextWriter using -// the JSON format. See http://json.org. -class JsonWriter : public StructuredWriter { - public: - // Construct a JsonWriter that writes to the specified TextWriter. - // Specify the number of spaces for each indentation level. - JsonWriter(TextWriter* writer, int indent_spaces); - - // Flushes the remaining output and closes the underlying TextWriter. - virtual ~JsonWriter(); - - // Writes the opening brace of an JSON object literal. - virtual void OpenObject(); - - // Writes the closing brace of an JSON object literal. - virtual void CloseObject(); - - // Writes the opening bracket of a JSON array literal. - virtual void OpenArray(); - - // Writes the closing bracket of a JSON array literal. - virtual void CloseArray(); - - // Disables redundant white space until compacting is closed. - // Can be nested. - virtual void BeginCompacting(); - - // Disables previously opened compacting. - virtual void EndCompacting(); - - // Writes the name of a property surrounded by quotes. Follow - // with a call to one of the functions that writes a value. - virtual void WritePropertyName(const std::string& name); - - // Writes a boolean literal. - virtual void WriteBool(bool value); - - // Writes a number literal. - virtual void WriteInt(int value); - - // Writes a number literal. - virtual void WriteUnsignedInt(unsigned int value); - - // Writes a number literal. - virtual void WriteFloat(float value); - - // Writes a string literal with JSON escape sequences for - // special characters. - virtual void WriteString(const std::string& value); - - // Writes a null literal. - virtual void WriteNull(); - - // Flushes the remaining output and closes the underlying TextWriter. - virtual void Close(); - - private: - void IncreaseIndentation(); - void DecreaseIndentation(); - void ScheduleNewLine(); - void ScheduleComma(); - void CancelComma(); - void WritePending(); - void WriteEscapedString(const std::string& unescaped); - - TextWriter* writer_; - int indent_spaces_; - int compacting_level_; - int current_indentation_; - bool new_line_pending_; - bool comma_pending_; - DISALLOW_COPY_AND_ASSIGN(JsonWriter); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_JSON_WRITER_H_ diff --git a/o3d/utils/cross/json_writer_test.cc b/o3d/utils/cross/json_writer_test.cc deleted file mode 100644 index ad00d8b..0000000 --- a/o3d/utils/cross/json_writer_test.cc +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of class JsonWriter. - -#include "tests/common/win/testing_common.h" -#include "utils/cross/json_writer.h" -#include "utils/cross/string_writer.h" - -namespace o3d { - -class JsonWriterTest : public testing::Test { - public: - JsonWriterTest() - : output_(StringWriter::CR_LF), - json_writer_(&output_, 2) { - } - protected: - StringWriter output_; - JsonWriter json_writer_; -}; - -TEST_F(JsonWriterTest, WritesEmptyObject) { - json_writer_.OpenObject(); - json_writer_.CloseObject(); - json_writer_.Close(); - ASSERT_EQ(String("{\r\n}\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesNestedObjects) { - json_writer_.OpenObject(); - json_writer_.OpenObject(); - json_writer_.CloseObject(); - json_writer_.OpenObject(); - json_writer_.CloseObject(); - json_writer_.CloseObject(); - json_writer_.Close(); - ASSERT_EQ(String("{\r\n {\r\n },\r\n {\r\n }\r\n}\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesObjectProperty) { - json_writer_.OpenObject(); - json_writer_.WritePropertyName(String("myProperty")); - json_writer_.WriteFloat(1.25f); - json_writer_.CloseObject(); - json_writer_.Close(); - ASSERT_EQ(String("{\r\n \"myProperty\": 1.25\r\n}\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, EscapesSpecialCharsInObjectPropertyName) { - json_writer_.OpenObject(); - json_writer_.WritePropertyName(String("\"\\\b\f\n\r\t\x01")); - json_writer_.WriteFloat(1.25f); - json_writer_.CloseObject(); - json_writer_.Close(); - ASSERT_EQ( - String("{\r\n \"\\\"\\\\\\b\\f\\n\\r\\t\\u0001\": 1.25\r\n}\r\n"), - output_.ToString()); -} -TEST_F(JsonWriterTest, WritesCommaSeparatedObjectProperties) { - json_writer_.OpenObject(); - json_writer_.WritePropertyName(String("myProperty1")); - json_writer_.WriteFloat(1.25f); - json_writer_.WritePropertyName(String("myProperty2")); - json_writer_.WriteFloat(2.5f); - json_writer_.CloseObject(); - json_writer_.Close(); - ASSERT_EQ( - String( - "{\r\n \"myProperty1\": 1.25,\r\n \"myProperty2\": 2.5\r\n}\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesEmptyArray) { - json_writer_.OpenArray(); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n]\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesNestedArrays) { - json_writer_.OpenArray(); - json_writer_.OpenArray(); - json_writer_.CloseArray(); - json_writer_.OpenArray(); - json_writer_.CloseArray(); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n [\r\n ],\r\n [\r\n ]\r\n]\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesArrayOfBools) { - json_writer_.OpenArray(); - json_writer_.WriteBool(false); - json_writer_.WriteBool(true); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n false,\r\n true\r\n]\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesArrayOfInts) { - json_writer_.OpenArray(); - json_writer_.WriteInt(1); - json_writer_.WriteInt(2); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n 1,\r\n 2\r\n]\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesArrayOfUnsignedInts) { - json_writer_.OpenArray(); - json_writer_.WriteUnsignedInt(1u); - json_writer_.WriteUnsignedInt(2u); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n 1,\r\n 2\r\n]\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesArrayOfFloats) { - json_writer_.OpenArray(); - json_writer_.WriteFloat(1); - json_writer_.WriteFloat(2); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n 1,\r\n 2\r\n]\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesArrayOfStrings) { - json_writer_.OpenArray(); - json_writer_.WriteString(String("abc")); - json_writer_.WriteString(String("def")); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n \"abc\",\r\n \"def\"\r\n]\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, EscapesSpecialCharsInString) { - json_writer_.WriteString(String("\"\\\b\f\n\r\t\x01")); - json_writer_.Close(); - ASSERT_EQ(String("\"\\\"\\\\\\b\\f\\n\\r\\t\\u0001\"\r\n"), - output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesArrayOfNulls) { - json_writer_.OpenArray(); - json_writer_.WriteNull(); - json_writer_.WriteNull(); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n null,\r\n null\r\n]\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, WritesWithoutWhiteSpaceIfCompacted) { - json_writer_.BeginCompacting(); - json_writer_.OpenObject(); - json_writer_.WritePropertyName(String("foo")); - json_writer_.WriteNull(); - json_writer_.WritePropertyName(String("bar")); - json_writer_.WriteNull(); - json_writer_.CloseObject(); - json_writer_.EndCompacting(); - json_writer_.Close(); - ASSERT_EQ(String("{\"foo\":null,\"bar\":null}\r\n"), output_.ToString()); -} - -TEST_F(JsonWriterTest, ShouldWritePendingWhiteSpaceBeforeCompactedElements) { - json_writer_.OpenArray(); - json_writer_.BeginCompacting(); - json_writer_.OpenObject(); - json_writer_.WritePropertyName(String("foo")); - json_writer_.WriteNull(); - json_writer_.CloseObject(); - json_writer_.EndCompacting(); - json_writer_.CloseArray(); - json_writer_.Close(); - ASSERT_EQ(String("[\r\n {\"foo\":null}\r\n]\r\n"), output_.ToString()); -} -} // namespace o3d diff --git a/o3d/utils/cross/math_gtest.cc b/o3d/utils/cross/math_gtest.cc deleted file mode 100644 index 1296817..0000000 --- a/o3d/utils/cross/math_gtest.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// This file defines the some helper for gtest for the math library used by O3D. - -#include "utils/cross/math_gtest.h" -#include "core/cross/types.h" - - -namespace Vectormath { -namespace Aos { - -bool operator==(const Vector4& left, const Vector4& right) { - return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && - left[3] == right[3]; -} - -bool operator!=(const Vector4& left, const Vector4& right) { - return !(left == right); -} - -bool operator==(const Matrix4& left, const Matrix4& right) { - return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && - left[3] == right[3]; -} - -bool operator!=(const Matrix4& left, const Matrix4& right) { - return !(left == right); -} - -std::ostream& operator<<(std::ostream& stream, const Vector4& value) { - stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", " - << value[3] << "}"; - return stream; -} - -std::ostream& operator<<(std::ostream& stream, const Matrix4& value) { - stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", " - << value[3] << "}"; - return stream; -} - -} // namespace Aos -} // namespace Vectormath - -namespace o3d { - -bool operator==(const Float2& left, const Float2& right) { - return left[0] == right[0] && left[1] == right[1]; -} - -bool operator!=(const Float2& left, const Float2& right) { - return !(left == right); -} - -bool operator==(const Float3& left, const Float3& right) { - return left[0] == right[0] && left[1] == right[1] && left[2] == right[2]; -} - -bool operator!=(const Float3& left, const Float3& right) { - return !(left == right); -} - -bool operator==(const Float4& left, const Float4& right) { - return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && - left[3] == right[3]; -} - -bool operator!=(const Float4& left, const Float4& right) { - return !(left == right); -} - -std::ostream& operator<<(std::ostream& stream, const Float2& value) { - stream << "{" << value[0] << ", " << value[1] << "}"; - return stream; -} - -std::ostream& operator<<(std::ostream& stream, const Float3& value) { - stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << "}"; - return stream; -} - -std::ostream& operator<<(std::ostream& stream, const Float4& value) { - stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", " - << value[3] << "}"; - return stream; -} - -} // namespace o3d - - diff --git a/o3d/utils/cross/math_gtest.h b/o3d/utils/cross/math_gtest.h deleted file mode 100644 index e411eac..0000000 --- a/o3d/utils/cross/math_gtest.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// This file declares the some helper for gtest for the math library used by -// O3D. - -#ifndef O3D_UTILS_CROSS_MATH_GTEST_H_ -#define O3D_UTILS_CROSS_MATH_GTEST_H_ - -#include <ostream> // NOLINT - -namespace Vectormath { -namespace Aos { -class Vector4; -class Matrix4; - -bool operator==(const Vector4& left, const Vector4& right); -bool operator!=(const Vector4& left, const Vector4& right); -bool operator==(const Matrix4& left, const Matrix4& right); -bool operator!=(const Matrix4& left, const Matrix4& right); -std::ostream& operator<<(std::ostream& stream, const Vector4& value); -std::ostream& operator<<(std::ostream& stream, const Matrix4& value); -} -} - -namespace o3d { -class Float2; -class Float3; -class Float4; - -bool operator==(const Float2& left, const Float2& right); -bool operator!=(const Float2& left, const Float2& right); -bool operator==(const Float3& left, const Float3& right); -bool operator!=(const Float3& left, const Float3& right); -bool operator==(const Float4& left, const Float4& right); -bool operator!=(const Float4& left, const Float4& right); -std::ostream& operator<<(std::ostream& stream, const Float2& value); -std::ostream& operator<<(std::ostream& stream, const Float3& value); -std::ostream& operator<<(std::ostream& stream, const Float4& value); -} - -#endif // O3D_UTILS_CROSS_MATH_GTEST_H_ - diff --git a/o3d/utils/cross/math_gtest_test.cc b/o3d/utils/cross/math_gtest_test.cc deleted file mode 100644 index ae6bc62..0000000 --- a/o3d/utils/cross/math_gtest_test.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tests/common/win/testing_common.h" -#include "utils/cross/math_gtest.h" - -namespace o3d { - -class MathGTestTest : public testing::Test { -}; - -// Test the math gtest helper functions. -TEST_F(MathGTestTest, TestMathGTest) { - EXPECT_EQ(Float2(1.2f, 2.3f), Float2(1.2f, 2.3f)); - EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.3f, 2.3f)); - EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.2f, 2.4f)); - EXPECT_EQ(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.5f)); - EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.3f, 2.3f, 4.5f)); - EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.4f, 4.5f)); - EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.6f)); - EXPECT_EQ(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.7f)); - EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.3f, 2.3f, 4.5f, 6.7f)); - EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.4f, 4.5f, 6.7f)); - EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.6f, 6.7f)); - EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.8f)); - Matrix4 a(Vector4(1.1f, 2.2f, 3.3f, 4.4f), - Vector4(1.2f, 2.3f, 3.4f, 4.5f), - Vector4(1.3f, 2.4f, 3.5f, 4.6f), - Vector4(1.4f, 2.5f, 3.6f, 4.7f)); - Matrix4 b(a); - EXPECT_EQ(a, b); - for (int ii = 0; ii < 4; ++ii) { - for (int jj = 0; jj < 4; ++jj) { - b = a; - b.setElem(ii, jj, b.getElem(ii, jj) * 2); - EXPECT_NE(a, b); - } - } -} - -} // namespace o3d - diff --git a/o3d/utils/cross/string_reader.cc b/o3d/utils/cross/string_reader.cc deleted file mode 100644 index c62669d..0000000 --- a/o3d/utils/cross/string_reader.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class StringReader. The -// tests are in string_reader_test.cc. - -#include <stdio.h> -#include "utils/cross/string_reader.h" - -namespace o3d { - -StringReader::StringReader(const std::string& input) - : TextReader(), input_(input), position_(0) { -} - -StringReader::~StringReader() { -} - -bool StringReader::IsAtEnd() const { - return position_ == input_.size(); -} - -std::string StringReader::PeekString( - std::string::size_type count) const { - count = std::min(input_.size() - position_, count); - if (count > 0) { - return input_.substr(position_, count); - } else { - return ""; - } -} - -char StringReader::ReadChar() { - if (position_ <= input_.size() && input_.size() > 0) { - position_++; - return input_[position_ - 1]; - } else { - return 0; - } -} - -std::string StringReader::ReadString(std::string::size_type count) { - count = std::min(input_.size() - position_, count); - std::string result; - if (count > 0) { - result = input_.substr(position_, count); - position_ += count; - } - return result; -} - -std::string StringReader::ReadLine() { - std::string::size_type possible_eol = input_.find_first_of("\r\n", position_); - if (possible_eol == std::string::npos) { - // There wasn't an end of line marker anywhere, so just return the - // whole string. - return ReadToEnd(); - } else { - if ((input_.size() - position_) > 1) { - // See which end of line marker we have and strip it. - int eol_len = TestForEndOfLine(input_.substr(possible_eol, 2)); - std::string result = input_.substr(position_, possible_eol - position_); - position_ = possible_eol + eol_len; - return result; - } else { - // If it's only one long, and it found a carriage return or a - // linefeed, then we just eat that character and return an - // empty string. - position_++; - return std::string(""); - } - } - return std::string(""); -} - -std::string StringReader::ReadToEnd() { - std::string result = input_.substr(position_); - position_ = input_.size(); - return result; -} -} // end namespace o3d diff --git a/o3d/utils/cross/string_reader.h b/o3d/utils/cross/string_reader.h deleted file mode 100644 index aea6ea6..0000000 --- a/o3d/utils/cross/string_reader.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class StringReader. - -#ifndef O3D_UTILS_CROSS_STRING_READER_H_ -#define O3D_UTILS_CROSS_STRING_READER_H_ - -#include <string> - -#include "utils/cross/text_reader.h" - -namespace o3d { - -// A StringReader reads a sequence of characters from an -// in-memory string. -class StringReader : public TextReader { - public: - // Prepare to read from the given input string. - explicit StringReader(const std::string& input); - virtual ~StringReader(); - - virtual bool IsAtEnd() const; - virtual std::string PeekString(std::string::size_type count) const; - virtual char ReadChar(); - virtual std::string ReadString(std::string::size_type count); - virtual std::string ReadLine(); - virtual std::string ReadToEnd(); - - // Access to the original input buffer, and the current position in - // that buffer. - const std::string& input() const { return input_; } - std::string::size_type position() const { return position_; } - - private: - std::string input_; - std::string::size_type position_; - DISALLOW_COPY_AND_ASSIGN(StringReader); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_STRING_READER_H_ diff --git a/o3d/utils/cross/string_reader_test.cc b/o3d/utils/cross/string_reader_test.cc deleted file mode 100644 index 1afab5e..0000000 --- a/o3d/utils/cross/string_reader_test.cc +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of class StringReader. -#include <stdio.h> - -#include "tests/common/win/testing_common.h" -#include "utils/cross/string_reader.h" - -namespace o3d { - -namespace { -static const char* kTestStrings[] = { - "testing 1..2..3", - "4..5..6", - "testing 1..2..3\n4..5..6\n", - "testing 1..2..3\r4..5..6\r", - "testing 1..2..3\r\n4..5..6\r\n", - "testing 1..2..3\n\r4..5..6\n\r", - "testing 1..2..3\n\n4..5..6\n\n", -}; -} // end anonymous namespace - -class StringReaderTest : public testing::Test { - public: - StringReaderTest() { - test_string_one_ = kTestStrings[0]; - test_string_two_ = kTestStrings[1]; - test_string_lf_ = kTestStrings[2]; - test_string_cr_ = kTestStrings[3]; - test_string_crlf_ = kTestStrings[4]; - test_string_lfcr_ = kTestStrings[5]; - test_string_lflf_ = kTestStrings[6]; - } - - std::string test_string_one_; - std::string test_string_two_; - std::string test_string_lf_; - std::string test_string_cr_; - std::string test_string_crlf_; - std::string test_string_lfcr_; - std::string test_string_lflf_; -}; - -TEST_F(StringReaderTest, StartAtBeginning) { - StringReader reader(test_string_one_); - EXPECT_EQ(0U, reader.position()); - EXPECT_EQ(test_string_one_, reader.input()); -} - -TEST_F(StringReaderTest, TestPeekString) { - StringReader reader(test_string_one_); - EXPECT_EQ(test_string_one_.substr(0, 6), reader.PeekString(6)); - EXPECT_EQ(0U, reader.position()); - EXPECT_EQ(test_string_one_, reader.input()); -} - -TEST_F(StringReaderTest, ReadsSingleCharacter) { - StringReader reader(test_string_one_); - EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); - EXPECT_EQ(1U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_one_.substr(1, 2), reader.PeekString(2)); - EXPECT_EQ(1U, reader.position()); -} - -TEST_F(StringReaderTest, ReadsMultipleCharacters) { - StringReader reader(test_string_one_); - EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); - EXPECT_EQ(test_string_one_.substr(1, 1)[0], reader.ReadChar()); - EXPECT_EQ(2U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_one_.substr(2, 2), reader.PeekString(2)); - EXPECT_EQ(2U, reader.position()); -} - -TEST_F(StringReaderTest, ReadsString) { - StringReader reader(test_string_one_); - EXPECT_EQ(test_string_one_.substr(0, 7), reader.ReadString(7)); - EXPECT_EQ(7U, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_one_.substr(7, 2), reader.PeekString(2)); - EXPECT_EQ(7U, reader.position()); -} - -TEST_F(StringReaderTest, ReadsToEnd) { - StringReader reader(test_string_lf_); - EXPECT_EQ(test_string_lf_, reader.ReadToEnd()); - EXPECT_EQ(test_string_lf_.size(), reader.position()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ("", reader.ReadString(1)); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lf_.size(), reader.position()); -} - - -TEST_F(StringReaderTest, ReadsLinefeedString) { - StringReader reader(test_string_lf_); - std::string line = reader.ReadLine(); - EXPECT_EQ(test_string_one_, line); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lf_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lf_.size(), reader.position()); -} - -TEST_F(StringReaderTest, ReadsCarriageReturnString) { - StringReader reader(test_string_cr_); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_cr_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_cr_.size(), reader.position()); -} - - -TEST_F(StringReaderTest, ReadsCarriageReturnLinefeedString) { - StringReader reader(test_string_crlf_); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 2, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_crlf_.substr(test_string_one_.size() + 2, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 2, reader.position()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_crlf_.size(), reader.position()); -} - -TEST_F(StringReaderTest, ReadsLinefeedCarriageReturnString) { - StringReader reader(test_string_lfcr_); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lfcr_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lfcr_.size(), reader.position()); -} - -TEST_F(StringReaderTest, ReadsLinefeedLinefeedString) { - StringReader reader(test_string_lflf_); - EXPECT_EQ(test_string_one_, reader.ReadLine()); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lflf_.substr(test_string_one_.size() + 1, 2), - reader.PeekString(2)); - EXPECT_EQ(test_string_one_.size() + 1, reader.position()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ(test_string_two_, reader.ReadLine()); - EXPECT_FALSE(reader.IsAtEnd()); - EXPECT_EQ("", reader.ReadLine()); - EXPECT_TRUE(reader.IsAtEnd()); - EXPECT_EQ(test_string_lflf_.size(), reader.position()); -} -} // namespace o3d diff --git a/o3d/utils/cross/string_writer.cc b/o3d/utils/cross/string_writer.cc deleted file mode 100644 index ccedeeb..0000000 --- a/o3d/utils/cross/string_writer.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class StringWriter. - -#include "utils/cross/string_writer.h" - -namespace o3d { - -StringWriter::StringWriter(NewLine new_line) - : TextWriter(new_line) { -} - -void StringWriter::WriteChar(char c) { - string_ += c; -} - -void StringWriter::WriteString(const std::string& s) { - string_ += s; -} - -std::string StringWriter::ToString() const { - return string_; -} - -} // namespace o3d diff --git a/o3d/utils/cross/string_writer.h b/o3d/utils/cross/string_writer.h deleted file mode 100644 index 823f15f..0000000 --- a/o3d/utils/cross/string_writer.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class StringWriter. - -#ifndef O3D_UTILS_CROSS_STRING_WRITER_H_ -#define O3D_UTILS_CROSS_STRING_WRITER_H_ - -#include <string> - -#include "utils/cross/text_writer.h" - -namespace o3d { - -// A StringWriter writes a sequence of characters to an -// in-memory string. -class StringWriter : public TextWriter { - public: - // Prepare to produce a string using the given new line - // sequence. - explicit StringWriter(NewLine new_line); - virtual void WriteChar(char c); - virtual void WriteString(const std::string& s); - - // Retrieve the string that has been produced so far. - std::string ToString() const; - private: - std::string string_; - DISALLOW_COPY_AND_ASSIGN(StringWriter); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_STRING_WRITER_H_ diff --git a/o3d/utils/cross/string_writer_test.cc b/o3d/utils/cross/string_writer_test.cc deleted file mode 100644 index 488bad0..0000000 --- a/o3d/utils/cross/string_writer_test.cc +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of class StringWriter. - -#include "tests/common/win/testing_common.h" -#include "utils/cross/string_writer.h" - -namespace o3d { - -class StringWriterTest : public testing::Test { -}; - -TEST_F(StringWriterTest, EmptyByDefault) { - StringWriter writer(StringWriter::CR); - EXPECT_EQ(String(), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesSingleCharacter) { - StringWriter writer(StringWriter::CR); - writer.WriteChar('y'); - EXPECT_EQ(String("y"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesMultipleCharacters) { - StringWriter writer(StringWriter::CR); - writer.WriteChar('y'); - writer.WriteChar('z'); - EXPECT_EQ(String("yz"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesString) { - StringWriter writer(StringWriter::CR); - writer.WriteString(String("hello")); - EXPECT_EQ(String("hello"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesCarriageReturnNewLine) { - StringWriter writer(StringWriter::CR); - writer.WriteNewLine(); - EXPECT_EQ(String("\r"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesCarriageReturnLineFeedNewLine) { - StringWriter writer(StringWriter::CR_LF); - writer.WriteNewLine(); - EXPECT_EQ(String("\r\n"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesLineFeedNewLine) { - StringWriter writer(StringWriter::LF); - writer.WriteNewLine(); - EXPECT_EQ(String("\n"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesFalse) { - StringWriter writer(StringWriter::LF); - writer.WriteBool(false); - EXPECT_EQ(String("false"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesTrue) { - StringWriter writer(StringWriter::LF); - writer.WriteBool(true); - EXPECT_EQ(String("true"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesInt) { - StringWriter writer(StringWriter::LF); - writer.WriteInt(-123); - EXPECT_EQ(String("-123"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesUnsignedInt) { - StringWriter writer(StringWriter::LF); - writer.WriteInt(123u); - ASSERT_EQ(String("123"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesFloat) { - StringWriter writer(StringWriter::LF); - writer.WriteFloat(1.25f); - EXPECT_EQ(String("1.25"), writer.ToString()); -} - -TEST_F(StringWriterTest, WritesPrintfFormatted) { - StringWriter writer(StringWriter::LF); - writer.WriteFormatted("%s: %d", "age", 31); - EXPECT_EQ(String("age: 31"), writer.ToString()); -} -} // namespace o3d diff --git a/o3d/utils/cross/structured_writer.h b/o3d/utils/cross/structured_writer.h deleted file mode 100644 index e25f615..0000000 --- a/o3d/utils/cross/structured_writer.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class StructuredWriter. - -#ifndef O3D_UTILS_CROSS_STRUCTURED_WRITER_H_ -#define O3D_UTILS_CROSS_STRUCTURED_WRITER_H_ - -#include <string> - -#include "base/basictypes.h" - -namespace o3d { - -// Interface of classes that can write structured data consisting of -// a hierarchy of objects (with named properties) and arrays of typed -// values. -class StructuredWriter { - public: - StructuredWriter() {} - virtual ~StructuredWriter() {} - - // Opens an object block. An object block contains property / value - // pairs. - virtual void OpenObject() = 0; - - // Closes an object block. - virtual void CloseObject() = 0; - - // Opens an array block. An array block contains zero or more values. - virtual void OpenArray() = 0; - - // Closes an array block. - virtual void CloseArray() = 0; - - // Hints to the writer that it should not add additional formatting - // to make the output more readable. These can be nested. - virtual void BeginCompacting() = 0; - - // Ends the hint that additional formatting is not necessary. - virtual void EndCompacting() = 0; - - // Writes the name of a property. This should be immediately by a - // value. - virtual void WritePropertyName(const std::string& name) = 0; - - // Writes a boolean value. - virtual void WriteBool(bool value) = 0; - - // Writes an integer value. - virtual void WriteInt(int value) = 0; - - // Writes an unsigned integer value. - virtual void WriteUnsignedInt(unsigned int value) = 0; - - // Writes a float value. - virtual void WriteFloat(float value) = 0; - - // Writes a string value. - virtual void WriteString(const std::string& value) = 0; - - // Writes a null value. - virtual void WriteNull() = 0; - - // Flushes any unwritten content and closes the writer. No further - // writes are allowed. - virtual void Close() {} - - private: - DISALLOW_COPY_AND_ASSIGN(StructuredWriter); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_STRUCTURED_WRITER_H_ diff --git a/o3d/utils/cross/temporary_file.cc b/o3d/utils/cross/temporary_file.cc deleted file mode 100644 index fb9e8de..0000000 --- a/o3d/utils/cross/temporary_file.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class TemporaryFile. - -#include "utils/cross/temporary_file.h" - -#include "base/file_path.h" -#include "base/file_util.h" - -namespace o3d { - -// TODO(gspencer): Remove this. This is a hack to prevent needing to -// merge all of chrome's base code into the google code O3D tree. -#ifndef GYP_BUILD -#define CreateTemporaryFile CreateTemporaryFileName -#endif - -namespace { -void DeletePath(const FilePath& path) { - if (!path.empty()) { - file_util::Delete(path, false); - } -} -} // end anonymous namespace - -TemporaryFile::TemporaryFile() { - // file_path_ is initialized to be empty. -} - -TemporaryFile::TemporaryFile(const FilePath& file_to_manage) - : file_path_(file_to_manage) { -} - -bool TemporaryFile::Create(TemporaryFile* temporary_file) { - FilePath temporary_path; - if (file_util::CreateTemporaryFile(&temporary_path)) { - temporary_file->Reset(temporary_path); - } else { - return false; - } - return true; -} - -TemporaryFile::~TemporaryFile() { - DeletePath(file_path_); -} - -FilePath TemporaryFile::Release() { - FilePath old_path = file_path_; - file_path_ = FilePath(); - return old_path; -} - -void TemporaryFile::Reset(const FilePath& file_path) { - DeletePath(file_path_); - file_path_ = file_path; -} - -} // end namespace o3d diff --git a/o3d/utils/cross/temporary_file.h b/o3d/utils/cross/temporary_file.h deleted file mode 100644 index f3cf383..0000000 --- a/o3d/utils/cross/temporary_file.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file declares a simple manager class that manages a temporary -// file. - -#ifndef O3D_UTILS_CROSS_TEMPORARY_FILE_H_ -#define O3D_UTILS_CROSS_TEMPORARY_FILE_H_ - -#include "base/file_path.h" - -namespace o3d { - -// TemporaryFile is a simple manager class that manages a temporary -// file. It accepts the path to the temporary file when it is -// created, and deletes the temporary file when it goes out of scope. -// It is up to the creator to verify that the program has the rights -// to delete the file given to it. -class TemporaryFile { - public: - // Creates an empty TemporaryFile object. Must call "reset" to have - // it manage a file. - TemporaryFile(); - - // Manages the given file path as a temporary file. - explicit TemporaryFile(const FilePath& file_to_manage); - ~TemporaryFile(); - - // Returns the currently managed path. - const FilePath& path() const { - return file_path_; - } - - // Releases the managed path so that it will NOT be deleted when - // this object goes out of scope. The path that was being managed - // is returned. - FilePath Release(); - - // Resets the path being managed to the supplied path. If this - // object was managing a file before, then that file will be - // immediately deleted. - void Reset(const FilePath& file_path); - - // Creates an empty temporary file in the system's default temporary - // directory and resets the given TemporaryFile object to manage - // that file. Returns true if it was successful in creating the - // file. - static bool Create(TemporaryFile* temp_file); - - private: - FilePath file_path_; - - DISALLOW_COPY_AND_ASSIGN(TemporaryFile); -}; - -} // end namespace o3d -#endif // O3D_UTILS_CROSS_TEMPORARY_FILE_H_ diff --git a/o3d/utils/cross/temporary_file_test.cc b/o3d/utils/cross/temporary_file_test.cc deleted file mode 100644 index d9ae361..0000000 --- a/o3d/utils/cross/temporary_file_test.cc +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the tests of class TemporaryFile. - -#include <stdio.h> - -#include "base/file_util.h" -#include "tests/common/win/testing_common.h" -#include "utils/cross/temporary_file.h" - -namespace o3d { - -// TODO(gspencer): Remove this once scons build is dead. This is a -// hack to prevent needing to merge all of chrome's base code into the -// google code O3D tree. -#ifndef GYP_BUILD -#define CreateTemporaryFile CreateTemporaryFileName -#endif - -class TemporaryFileTest : public testing::Test { -}; - -TEST_F(TemporaryFileTest, BasicConstruction) { - TemporaryFile temporary_file; - EXPECT_TRUE(temporary_file.path().empty()); -} - -TEST_F(TemporaryFileTest, BasicFunction) { - FilePath path; - file_util::CreateTemporaryFile(&path); - EXPECT_TRUE(file_util::PathExists(path)); - { - TemporaryFile temporary_file(path); - EXPECT_TRUE(file_util::PathExists(path)); - EXPECT_EQ(path.value(), temporary_file.path().value()); - EXPECT_TRUE(file_util::PathExists(temporary_file.path())); - } - EXPECT_FALSE(file_util::PathExists(path)); -} - -TEST_F(TemporaryFileTest, Reset) { - FilePath path; - FilePath path1; - file_util::CreateTemporaryFile(&path); - file_util::CreateTemporaryFile(&path1); - EXPECT_TRUE(file_util::PathExists(path)); - EXPECT_TRUE(file_util::PathExists(path1)); - { - TemporaryFile temporary_file(path1); - EXPECT_EQ(path1.value(), temporary_file.path().value()); - EXPECT_TRUE(file_util::PathExists(path1)); - EXPECT_TRUE(file_util::PathExists(temporary_file.path())); - temporary_file.Reset(path); - EXPECT_TRUE(file_util::PathExists(path)); - EXPECT_EQ(path.value(), temporary_file.path().value()); - EXPECT_FALSE(file_util::PathExists(path1)); - EXPECT_TRUE(file_util::PathExists(path)); - EXPECT_TRUE(file_util::PathExists(temporary_file.path())); - } - EXPECT_FALSE(file_util::PathExists(path)); - EXPECT_FALSE(file_util::PathExists(path1)); -} - -TEST_F(TemporaryFileTest, Release) { - FilePath path; - file_util::CreateTemporaryFile(&path); - EXPECT_TRUE(file_util::PathExists(path)); - { - TemporaryFile temporary_file(path); - EXPECT_TRUE(file_util::PathExists(path)); - EXPECT_TRUE(file_util::PathExists(temporary_file.path())); - temporary_file.Release(); - } - EXPECT_TRUE(file_util::PathExists(path)); -} - -TEST_F(TemporaryFileTest, Create) { - FilePath test_path; - { - TemporaryFile temporary_file; - TemporaryFile::Create(&temporary_file); - EXPECT_FALSE(temporary_file.path().empty()); - EXPECT_TRUE(file_util::PathExists(temporary_file.path())); - EXPECT_TRUE(file_util::PathIsWritable(temporary_file.path())); - test_path = temporary_file.path(); - } - EXPECT_FALSE(file_util::PathExists(test_path)); -} - -} // namespace o3d diff --git a/o3d/utils/cross/text_reader.cc b/o3d/utils/cross/text_reader.cc deleted file mode 100644 index c6f1e56..0000000 --- a/o3d/utils/cross/text_reader.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class TextReader. The -// tests are in string_reader_test.cc. - -#include "utils/cross/text_reader.h" - -namespace o3d { -namespace { -static const char kLinefeed = '\n'; -static const char kCarriageReturn = '\r'; -} - -TextReader::TextReader() { -} - -TextReader::~TextReader() { -} - -int TextReader::TestForEndOfLine(const std::string& eol) { - if (eol.empty()) { - return 0; - } - if (eol[0] == kLinefeed) { - return 1; - } - if (eol[0] == kCarriageReturn) { - if (eol.size() > 1 && eol[1] == kLinefeed) { - return 2; - } else { - return 1; - } - } - return 0; -} -} // end namespace o3d diff --git a/o3d/utils/cross/text_reader.h b/o3d/utils/cross/text_reader.h deleted file mode 100644 index 470b666..0000000 --- a/o3d/utils/cross/text_reader.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class TextReader. - -#ifndef O3D_UTILS_CROSS_TEXT_READER_H_ -#define O3D_UTILS_CROSS_TEXT_READER_H_ - -#include <string> -#include "base/basictypes.h" - -namespace o3d { - -// TextReader is the abstract base class of classes -// that read a sequence of characters to an underlying -// medium. -class TextReader { - public: - // Construct a new TextReader. - TextReader(); - virtual ~TextReader(); - - // Returns true if at the end of the input. - virtual bool IsAtEnd() const = 0; - - // Read ahead up to count characters and return them as a string, - // but don't modify the input's current position. Returns the empty - // string if at the end of the input. - virtual std::string PeekString(std::string::size_type count) const = 0; - - // Read a single character. - virtual char ReadChar() = 0; - - // Read a number of characters as a string. If the input isn't that - // long, the string may be shorter than the given number of - // characters. Returns an empty string if it is already at the end - // of the input or if there is an error. - virtual std::string ReadString(std::string::size_type count) = 0; - - // Read a line of text, terminated by any kind of line terminator - // (LF/CRLF/CR). Returns the empty string if at end of input, or if - // there is an error. - virtual std::string ReadLine() = 0; - - // Read the remaining file into a string, linefeeds and all. - // Returns the empty string if already at the end of the file or - // there is an error. - virtual std::string ReadToEnd() = 0; - - protected: - // Returns length of EOL marker (one or two characters) if the given - // character string starts with an end of line marker. Returns zero - // if there is no EOL marker at the BEGINNING of the string. - static int TestForEndOfLine(const std::string& eol); - - private: - - DISALLOW_COPY_AND_ASSIGN(TextReader); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_TEXT_READER_H_ diff --git a/o3d/utils/cross/text_writer.cc b/o3d/utils/cross/text_writer.cc deleted file mode 100644 index 01dca8d..0000000 --- a/o3d/utils/cross/text_writer.cc +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the definition of class TextWriter. The -// tests are in string_writer_test.cc. - -#include <stdarg.h> - -#include "utils/cross/text_writer.h" -#include "base/string_util.h" - -using std::string; - -namespace o3d { -TextWriter::TextWriter(NewLine new_line) - : new_line_(new_line) { -} - -TextWriter::~TextWriter() { -} - -void TextWriter::WriteString(const string& s) { - for (size_t i = 0; i != s.length(); ++i) { - WriteChar(s[i]); - } -} - -void TextWriter::WriteBool(bool value) { - if (value) { - WriteString(string("true")); - } else { - WriteString(string("false")); - } -} - -void TextWriter::WriteInt(int value) { - WriteString(StringPrintf("%d", value)); -} - -void TextWriter::WriteUnsignedInt(unsigned int value) { - WriteString(StringPrintf("%u", value)); -} - -void TextWriter::WriteFloat(float value) { - WriteString(StringPrintf("%g", value)); -} - -void TextWriter::WriteFormatted(const char* format, ...) { - va_list args; - va_start(args, format); - string formatted; - StringAppendV(&formatted, format, args); - va_end(args); - - WriteString(formatted); -} - -void TextWriter::WriteNewLine() { - switch (new_line_) { - case CR: - WriteChar('\r'); - break; - case CR_LF: - WriteChar('\r'); - WriteChar('\n'); - break; - case LF: - WriteChar('\n'); - break; - } -} - -void TextWriter::Close() { -} -} // namespace o3d diff --git a/o3d/utils/cross/text_writer.h b/o3d/utils/cross/text_writer.h deleted file mode 100644 index 59fab88..0000000 --- a/o3d/utils/cross/text_writer.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2009, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -// This file contains the declaration of class TextWriter. - -#ifndef O3D_UTILS_CROSS_TEXT_WRITER_H_ -#define O3D_UTILS_CROSS_TEXT_WRITER_H_ - -#include <string> - -#include "base/basictypes.h" - -namespace o3d { - -// TextWriter is the abstract base class of classes -// that write a sequence of characters to an underlying -// medium. -class TextWriter { - public: - enum NewLine { - LF, - CR_LF, - CR, - }; - - // Construct a new TextWriter using the given newline - // sequence. - explicit TextWriter(NewLine new_line); - virtual ~TextWriter(); - - // Write a single character. - virtual void WriteChar(char c) = 0; - - // Write a string of characters. - virtual void WriteString(const std::string& s); - - // Write "true" or "false". - void WriteBool(bool value); - - // Write a signed integer. - void WriteInt(int value); - - // Write an unsigned integer. - void WriteUnsignedInt(unsigned int value); - - // Write a floating point number. - void WriteFloat(float value); - - // Write a printf formatted string. - void WriteFormatted(const char* format, ...); - - // Write a newline. - void WriteNewLine(); - - // Close the writer. - virtual void Close(); - - NewLine new_line() const { return new_line_; } - - private: - NewLine new_line_; - DISALLOW_COPY_AND_ASSIGN(TextWriter); -}; -} // namespace o3d - -#endif // O3D_UTILS_CROSS_TEXT_WRITER_H_ |