Skip to content

Commit c3f0722

Browse files
committed
Reslove conflict
2 parents 4960eb4 + 1a72fce commit c3f0722

49 files changed

Lines changed: 748 additions & 500 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/Testing
1111
/Makefile
1212
/native_test
13+
/native_test_c
14+
/native_test_cpp
1315
/native.cbp
1416
/native
1517
/libnative.a
@@ -20,7 +22,4 @@
2022
/test.txt
2123
/logging
2224
/json
23-
<<<<<<< HEAD
2425
/native.iml
25-
=======
26-
>>>>>>> 6fe558dd88a596443eee2ebb492aaf90de2d7c9d

CMakeLists.txt

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ endif ()
9494
# Dynamic linked library for OSX
9595
set(DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH})
9696

97+
# Only header files
98+
file(GLOB_RECURSE HEADERS
99+
./*.h
100+
library.hpp
101+
)
102+
97103
# Include all C/C++ and Unix Assembly files
98-
file(GLOB_RECURSE SOURCES
104+
file(GLOB_RECURSE SOURCES_C
99105
common/*
100106
crypto/*
101107
datetime/*
102-
java/*
103108
math/*
104109
network/*
105110
server/*
@@ -111,17 +116,11 @@ file(GLOB_RECURSE SOURCES
111116
validator/*
112117
)
113118

114-
file(GLOB_RECURSE HEADERS
115-
./*.h
116-
library.hpp
117-
)
118-
119-
# Include all unit test cases
120-
file(GLOB_RECURSE TESTS
119+
# Include all C unit test cases
120+
file(GLOB_RECURSE TESTS_C
121121
common/*_test.c
122122
crypto/*_test.c
123123
datetime/*_test.c
124-
java/**/*Test.cpp
125124
math/*_test.c
126125
network/*_test.c
127126
server/*_test.c
@@ -134,16 +133,32 @@ file(GLOB_RECURSE TESTS
134133
)
135134

136135
# Remove all test files within c files
137-
foreach (test ${TESTS})
138-
list(REMOVE_ITEM SOURCES ${test})
136+
foreach (test_c_file ${TESTS_C})
137+
list(REMOVE_ITEM SOURCES_C ${test_c_file})
138+
endforeach ()
139+
140+
# Only C++ unit test files
141+
file(GLOB_RECURSE SOURCES_CPP
142+
java/**/*.cpp
143+
)
144+
145+
# Only C++ unit test files
146+
file(GLOB_RECURSE TESTS_CPP
147+
java/**/*Test.cpp
148+
)
149+
150+
# Remove all test files within cpp files
151+
foreach (test_cpp_file ${TESTS_CPP})
152+
list(REMOVE_ITEM SOURCES_CPP ${test_cpp_file})
139153
endforeach ()
140154

141155
# Create test binary for testing
142-
add_executable(${PROJECT_NAME}_test ${TESTS} ${SOURCES} misc/unit-test.c)
156+
add_executable(${PROJECT_NAME}_test_c ${TESTS_C} ${SOURCES_C} misc/unit-test.c)
157+
add_executable(${PROJECT_NAME}_test ${TESTS_C} ${SOURCES_C} ${TESTS_CPP} ${SOURCES_CPP} misc/unit-test.c)
143158

144159
# Create native library for static linking
145-
add_library(${PROJECT_NAME}_static ${SOURCES})
146-
add_library(${PROJECT_NAME} SHARED ${SOURCES} java/lang/Character/Character_Test.cpp)
160+
add_library(${PROJECT_NAME}_static ${SOURCES_C} ${SOURCES_CPP})
161+
add_library(${PROJECT_NAME} SHARED ${SOURCES_C} ${SOURCES_CPP})
147162

148163
# Add make test
149164
add_custom_target(
@@ -159,8 +174,26 @@ add_custom_target(
159174

160175
# Check memory leak
161176
add_custom_target(
162-
leak
163-
COMMAND valgrind --error-exitcode=42 --leak-check=full ./native_test
177+
leak
178+
COMMAND valgrind --track-origins=yes --error-exitcode=2 --show-leak-kinds=all --leak-check=full ./native_test
179+
)
180+
181+
# Check memory leak
182+
add_custom_target(
183+
leak-debug
184+
COMMAND valgrind --gen-suppressions=yes --track-origins=yes --error-exitcode=2 --show-leak-kinds=all --leak-check=full ./native_test
185+
)
186+
187+
# Check memory leak
188+
add_custom_target(
189+
leak-c
190+
COMMAND valgrind --track-origins=yes --error-exitcode=2 --show-leak-kinds=all --leak-check=full ./native_test_c
191+
)
192+
193+
# Check memory leak
194+
add_custom_target(
195+
leak-c-debug
196+
COMMAND valgrind --gen-suppressions=yes --track-origins=yes --error-exitcode=2 --show-leak-kinds=all --leak-check=full ./native_test_c
164197
)
165198

166199
# Add make installation - install to Unix system
@@ -173,11 +206,13 @@ install(FILES ${HEADERS} DESTINATION include/native)
173206
# Link library for OSX and other platform
174207
# Darwin platform no need to link realtime library (-lrt)
175208
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
176-
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto)
177-
target_link_libraries(${PROJECT_NAME}_static ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto)
178-
target_link_libraries(${PROJECT_NAME}_test ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto)
209+
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm)
210+
target_link_libraries(${PROJECT_NAME}_static ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm)
211+
target_link_libraries(${PROJECT_NAME}_test ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm)
212+
target_link_libraries(${PROJECT_NAME}_test_c ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm)
179213
else ()
180-
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lrt)
181-
target_link_libraries(${PROJECT_NAME}_static ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lrt)
182-
target_link_libraries(${PROJECT_NAME}_test ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lrt)
214+
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm -lrt)
215+
target_link_libraries(${PROJECT_NAME}_static ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm -lrt)
216+
target_link_libraries(${PROJECT_NAME}_test ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm -lrt)
217+
target_link_libraries(${PROJECT_NAME}_test_c ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} -lcrypto -lm -lrt)
183218
endif ()

README.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Native Library
22

3-
[![Build Status](https://travis-ci.com/foodtiny/native.svg?token=p64HTBqDyw43Lh5iDLxP&branch=master)](https://travis-ci.com/foodtiny/native)
3+
[![Build Status](https://travis-ci.org/foodtiny/native.svg?branch=master)](https://travis-ci.org/foodtiny/native)
44
&nbsp;[![Support Platform](https://img.shields.io/badge/platform-linux%20%7C%20osx-blue.svg)]()&nbsp;&nbsp;[![License](https://img.shields.io/badge/license-apache-yellowgreen.svg)]()
55

66
**Native Library** provides low-level optimization and productivity for C/C++ application.
@@ -89,14 +89,15 @@ $ ./native
8989
#### Mock Server
9090
To test third parties we need to setup a server to mock http request from them.
9191
By running `make server`, it will serve in http://localhost:9999. You will see `Hi guys!` in there.
92+
Please keep this terminal running during your development.
9293
```bash
9394
$ make server
9495
```
9596

9697
#### Memory Leak
9798
Valgrind helps us in checking memory leak, you've just need to run
9899
```
99-
$ make leak
100+
$ cmake . && make native_test && make leak
100101
```
101102
It will tell you issues relate to memory.
102103

@@ -122,7 +123,7 @@ TEST(YourTestSuite, YourTestCase) {
122123
- At least one contributor in this project reviews your commits (except you) before merging
123124
- Best practices guidelines in [CONTRIBUTION.md](https://github.com/foodtiny/native/tree/master/CONTRIBUTION.md)
124125
125-
# Copyright & license
126+
### Copyright & license
126127
Copyright © 2014-2016 Food Tiny. All rights reserved, except as follows. Code is released under the Apache 2.0 license.
127128
You may obtain a duplicate copy of the same license, titled CC-BY-SA-4.0, at http://creativecommons.org/licenses/by/4.0/.
128129
Terms and conditions set forth in the file [LICENSE.docs](https://github.com/foodtiny/native/tree/master/LICENSE.docs).
@@ -131,22 +132,50 @@ Terms and conditions set forth in the file [LICENSE.docs](https://github.com/foo
131132
#### Differences
132133
This library provides Java classes in C++ so its syntax is friendly for
133134
both programming languges but we still have some issues :
135+
136+
- Namespace - Package
137+
```java
138+
// Java
139+
System.out.println("Java");
140+
```
141+
```cpp
142+
// C++
143+
System::out::println("C++");
144+
```
134145
- Array
146+
```java
147+
// Java
148+
byte[] byes = {};
149+
```
150+
```cpp
151+
// C++
152+
Array<byte> bytes = {};
153+
```
135154
- Interface
155+
```
156+
Comming soon
157+
```
136158
- Runtime
159+
```
160+
Comming soon
161+
```
137162
- Garbage Collection
163+
```
164+
Comming soon
165+
```
138166

139167
#### Data Types
140168
All data types are implemented and ready to use in C++ Application
141-
- [x] char - Java & C++
142-
- [x] byte - Java & C++ (equivalent with `unsigned char`)
143-
- [x] string - C++ (equivalent with `char*`)
144-
- [x] short - Java & C++
145-
- [x] int - Java & C++
146-
- [x] long - Java & C++
147-
- [x] float - Java & C++
148-
- [x] double - Java & C++
149-
- [x] boolean - Java & C++ (equivalent with `bool`)
169+
- [x] char - Java.Lang.Character
170+
- [x] byte - Java.Lang.Byte (equivalent with `unsigned char`)
171+
- [x] string - Java.Lang.String (equivalent with `char*`, Java does not have data type `string`)
172+
- [x] short - Java.Lang.Short
173+
- [x] int - Java.Lang.Integer
174+
- [x] long - Java.Lang.Long
175+
- [x] float - Java.Lang.Float
176+
- [x] double - Java.Lang.Double
177+
- [x] boolean - Java.Lang.Boolean (equivalent with `bool`)
178+
- [ ] enum - Java.Lang.Enum
150179

151180
#### Java Standard Packages
152181
All Java packages are in transformation so we can have a general look about road map

common/append_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ TEST (Common, AppendPointerChar) {
5353
ASSERT_STR("lazy", result[ 7 ]);
5454
ASSERT_STR("dog", result[ 8 ]);
5555
append = "";
56+
free(result);
5657
result = append_pointer_char(target, append);
5758
ASSERT_EQUAL(9, length_pointer_pointer_char(result));
59+
free(result);
5860
}
5961

6062

common/join_test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ TEST (Common, JoinPointerPointerChar) {
4141
'\0'
4242
};
4343
char *expect = "Thequickbrownfoxjumpsoverthelazydog";
44-
ASSERT_STR(expect, join_pointer_pointer_char(target));
44+
char *result = join_pointer_pointer_char(target);
45+
ASSERT_STR(expect, result);
46+
free(result);
4547
}
4648

4749
TEST (Common, JoinDelimiterPointerPointerChar) {
@@ -60,5 +62,7 @@ TEST (Common, JoinDelimiterPointerPointerChar) {
6062

6163
char *delimiter = "|";
6264
char *expect = "The|quick|brown|fox|jumps|over|the|lazy|dog";
63-
ASSERT_STR(expect, join_delimiter_pointer_pointer_char(target, delimiter));
65+
char *result = join_delimiter_pointer_pointer_char(target, delimiter);
66+
ASSERT_STR(expect, result);
67+
free(result);
6468
}

common/length.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "../string.h"
2828
#include "../common.h"
2929
#include "../type.h"
30+
#include <stdlib.h>
3031

3132
#define P_LEN(TYPE); \
3233
inline int length_pointer_##TYPE(TYPE *target) {\
@@ -49,7 +50,9 @@ inline int length_pointer_pointer_##TYPE(TYPE **target) {\
4950
#define NUM_LEN(TYPE); \
5051
inline int length_##TYPE(TYPE target) {\
5152
char *result = string_from_##TYPE(target);\
52-
return length_pointer_char(result);\
53+
int len = length_pointer_char(result); \
54+
free(result); \
55+
return len; \
5356
}
5457

5558
#ifdef __APPLE__
@@ -59,5 +62,5 @@ P_P_LEN(char);
5962
NUM_LEN(short);
6063
NUM_LEN(int);
6164
NUM_LEN(long);
62-
NUM_LEN(double)
63-
;NUM_LEN(float);
65+
NUM_LEN(double);
66+
NUM_LEN(float);

common/length_test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ TEST (Common, LengthPointerChar) {
3131
char *data = "Hello world";
3232
ASSERT_EQUAL(11, length_pointer_char(data));
3333

34+
ASSERT_EQUAL(11, length_pointer_char("Hello world"));
35+
3436
data = "";
3537
ASSERT_EQUAL(0, length_pointer_char(data));
3638

@@ -39,6 +41,11 @@ TEST (Common, LengthPointerChar) {
3941

4042
data = NULL;
4143
ASSERT_EQUAL(0, length_pointer_char(data));
44+
45+
// Please use calloc instead of malloc because it is dangerous
46+
// data = malloc(10);
47+
// ASSERT_EQUAL(0, length_pointer_char(data));
48+
// free(data);
4249
}
4350

4451
TEST (Common, LengthPointerPointerChar) {

0 commit comments

Comments
 (0)