-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow CFString code testing on non-Apple systems
- Loading branch information
1 parent
f0473b5
commit d3d5d49
Showing
6 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* Mocked CFString implementation | ||
*/ | ||
#include "CoreFoundation/CFString.h" | ||
#include <apr_pools.h> | ||
#include <exception> | ||
|
||
namespace { | ||
int throw_out_of_mem(int status) | ||
{ | ||
throw std::bad_alloc(); | ||
return status; | ||
} | ||
apr_pool_t* getStringPool() | ||
{ | ||
static struct cfstring_pool | ||
{ | ||
apr_pool_t* ptr = 0; | ||
cfstring_pool() | ||
{ | ||
apr_pool_create_core_ex(&ptr, throw_out_of_mem, NULL); | ||
} | ||
~cfstring_pool() | ||
{ | ||
apr_pool_destroy(ptr); | ||
} | ||
} pool; | ||
return pool.ptr; | ||
} | ||
} // namespace | ||
|
||
extern "C" { | ||
|
||
CFRange CFRangeMake(CFIndex loc, CFIndex len) { | ||
CFRange result; | ||
result.location = loc; | ||
result.length = len; | ||
return result; | ||
} | ||
|
||
CFIndex CFStringGetLength(CFStringRef theString) { | ||
UniChar* data = (UniChar*)theString; | ||
CFIndex result = 0; | ||
while (data[result]) | ||
++result; | ||
return result; | ||
} | ||
void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer) { | ||
UniChar* data = (UniChar*)theString; | ||
CFIndex index = 0; | ||
while (index < range.length) { | ||
*buffer = data[range.location + index]; | ||
++index; | ||
++buffer; | ||
} | ||
} | ||
CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars) { | ||
return (CFStringRef)apr_palloc(getStringPool(), (numChars + 1) * sizeof(UniChar)); | ||
} | ||
CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding) { | ||
UniChar* result = (UniChar*)apr_palloc(getStringPool(), (strlen(cStr) + 1) * sizeof(UniChar)); | ||
for (UniChar *p = result; *p++ = *cStr++;) | ||
; | ||
return (CFStringRef)result; | ||
} | ||
|
||
} // extern "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Build the MockCoreFoundation library | ||
add_library(MockCoreFoundation STATIC CFString.cpp) | ||
target_compile_definitions(MockCoreFoundation PRIVATE ${APR_COMPILE_DEFINITIONS}) | ||
target_include_directories(MockCoreFoundation INTERFACE PRIVATE ${APR_INCLUDE_DIR}) | ||
|
||
# Add to log4cxx as a dependency | ||
target_link_libraries(log4cxx PRIVATE MockCoreFoundation) | ||
target_include_directories(log4cxx INTERFACE PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Mocked CFString.h | ||
*/ | ||
#include <stdint.h> | ||
#if !defined(__COREFOUNDATION_CFSTRING__) | ||
#define __COREFOUNDATION_CFSTRING__ 1 | ||
extern "C" { | ||
typedef unsigned short UniChar; | ||
typedef long CFIndex; | ||
typedef struct __CFRange { | ||
CFIndex location; | ||
CFIndex length; | ||
} CFRange; | ||
typedef const struct __CFString* CFStringRef; | ||
typedef const struct __CFAllocator* CFAllocatorRef; | ||
typedef uint32_t CFStringEncoding; | ||
CFRange CFRangeMake(CFIndex loc, CFIndex len); | ||
CFIndex CFStringGetLength(CFStringRef theString); | ||
void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer); | ||
CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars); | ||
CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding); | ||
#define kCFAllocatorDefault 0 | ||
#define CFSTR(cStr) CFStringCreateWithCString(kCFAllocatorDefault, cStr, 0) | ||
} | ||
#endif /* ! __COREFOUNDATION_CFSTRING__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters