Skip to content

Commit

Permalink
Merged in development (pull request #10)
Browse files Browse the repository at this point in the history
Release v1.0.6
  • Loading branch information
Loi Nguyen committed Jul 27, 2018
2 parents 021b0d7 + 1b4b7fe commit 2481aa1
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 116 deletions.
30 changes: 15 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,23 @@ endforeach ()
add_library(${PROJECT_NAME} SHARED ${SOURCES_CPP})
add_library(${PROJECT_NAME}_static STATIC ${SOURCES_CPP})

# Link library for OSX and other platform
# Darwin platform no need to link realtime library (-lrt)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH})
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lm)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lm -lrt)
else ()
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lm)
endif ()

# Add make installation - install to Unix system
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
install(TARGETS ${PROJECT_NAME} DESTINATION ../lib OPTIONAL)
install(TARGETS ${PROJECT_NAME}_static DESTINATION ../lib OPTIONAL)
install(FILES library.hpp DESTINATION ../include/native)
install(DIRECTORY library DESTINATION ../include/native FILES_MATCHING PATTERN "*.hpp")
install(TARGETS ${PROJECT_NAME} DESTINATION lib OPTIONAL)
install(TARGETS ${PROJECT_NAME}_static DESTINATION lib OPTIONAL)
install(FILES library.hpp DESTINATION include/native)
install(DIRECTORY library DESTINATION include/native FILES_MATCHING PATTERN "*.hpp")

# Detect operating system
find_file(DEBIAN debian_version debconf.conf PATHS /etc)
Expand Down Expand Up @@ -129,14 +140,3 @@ add_custom_target(
COMMAND rm -rf /usr/include/native
COMMAND rm -rf /usr/lib/libnative*
)

# Link library for OSX and other platform
# Darwin platform no need to link realtime library (-lrt)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH})
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lm)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lm -lrt)
else ()
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} -lm)
endif ()
53 changes: 27 additions & 26 deletions library/Java/Lang/Enum/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,31 @@ namespace Java {
namespace Lang {
template<typename E>
class Enum : public Object,
//public virtual Comparable<E>,
public virtual Serializable {
//public virtual Comparable<E>,
public virtual Serializable {
private:
string name;
int original;
string originalString;
String enumName;
int ordinalNumber;

public:
Enum(const_string name, int original) {
this->name = stringCopy(name);
this->original = original;
this->originalString = stringCopy("");
Enum(const_string enumName, int ordinalNumber) : enumName(enumName), ordinalNumber(ordinalNumber) {

}

Enum(string name, int original) {
this->name = stringCopy(name);
this->original = original;
this->originalString = stringCopy("");
Enum(String enumName, int ordinalNumber) : enumName(enumName), ordinalNumber(ordinalNumber) {

}

~Enum() {
free(this->name);
free(this->originalString);
Enum(string enumName, int ordinalNumber) : enumName(enumName), ordinalNumber(ordinalNumber) {

}


public:
Enum clone() {
Enum result;
result.name = this->name;
result.original = this->original;
result.enumName = this->enumName;
result.ordinalNumber = this->ordinalNumber;
return result;
}

Expand All @@ -73,34 +68,40 @@ namespace Java {
* @return int
*/
int compareTo(const Enum<E> &e) {
return this->original - e.original;
return this->ordinalNumber - e.ordinalNumber;
}

/**
* Returns the name of this enum constant, exactly as declared in its enum declaration.
* @return String
*/
String getName() {
return this->name;
String name() {
return this->enumName;
}

/**
* Returns the original of this enumeration constant
* (its position in its enum declaration, where the initial constant is assigned an original of zero).
* @return int
*/
int getOrdinal() {
return this->original;
int ordinal() {
return this->ordinalNumber;
}

/**
* Returns the name of this enum constant, as contained in the declaration.
* @return String
*/
String toString() {
free(this->originalString);
asprintf(&this->originalString, "%d", this->original);
return this->originalString;
return this->enumName;
}

/**
* Returns true if the specified object is equal to this enum constant
* @return boolean
*/
boolean equals(Enum<E> &other) {
return this->ordinalNumber == other.ordinalNumber;
}
};
}
Expand Down
17 changes: 14 additions & 3 deletions library/Java/Lang/Enum/EnumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,29 @@ TEST (JavaLangEnum, GetName) {
// Given valid enum and name to test getName()
Enum<Integer> validEnum = Enum<Integer>("validName", 7);
String expectedValue = "validName";
assertEquals(expectedValue.toString(), validEnum.getName().toString());
assertEquals(expectedValue.toString(), validEnum.name().toString());
}

TEST (JavaLangEnum, GetOrdinal) {
// Given valid enum and name to test getOrdinal()
Enum<Integer> validEnum = Enum<Integer>("validName", 18);
int expectedValue = 18;
assertEquals(expectedValue, validEnum.getOrdinal());
assertEquals(expectedValue, validEnum.ordinal());
}

TEST (JavaLangEnum, ToString) {
// Given valid enum and name to test getOrdinal()
Enum<Integer> validEnum = Enum<Integer>("validName", 18);
assertEquals("18", validEnum.toString());
assertEquals("validName", validEnum.toString());
}

TEST (JavaLangEnum, equals) {
// Compare 2 equals enum - Return true
Enum<Integer> enum1 = Enum<Integer>("enum1", 1);
Enum<Integer> enum2 = Enum<Integer>("enum2", 1);
assertTrue(enum1.equals(enum2) == true);

// Compare 2 unequal enum - Return false
Enum<Integer> enum3 = Enum<Integer>("enum3", 3);
assertTrue(enum1.equals(enum3) == 0);
}
10 changes: 5 additions & 5 deletions library/Java/Lang/Object/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace Java {
* be cloned.
* @see java.lang.Cloneable
*/
Object &clone() throw (CloneNotSupportedException) {
Object &clone() {
throw CloneNotSupportedException();
}

Expand Down Expand Up @@ -284,7 +284,7 @@ namespace Java {
*
* @throws Throwable the {@code Exception} raised by this method
*/
void finalize() throw(Throwable);
void finalize();

public:
/**
Expand Down Expand Up @@ -389,7 +389,7 @@ namespace Java {
* @see java.lang.Object#notify()
* @see java.lang.Object#notifyAll()
*/
virtual void wait() throw(InterruptedException) final {
virtual void wait() final {
throw InterruptedException();
}

Expand Down Expand Up @@ -478,7 +478,7 @@ namespace Java {
* @see java.lang.Object#notify()
* @see java.lang.Object#notifyAll()
*/
virtual void wait(int timeout) throw(InterruptedException) final {
virtual void wait(int timeout) final {
throw InterruptedException();
}

Expand Down Expand Up @@ -544,7 +544,7 @@ namespace Java {
* status</i> of the current thread is cleared when
* this exception is thrown.
*/
virtual void wait(int timeout, int nanos) throw(InterruptedException) final {
virtual void wait(int timeout, int nanos) final {
throw InterruptedException();
}

Expand Down
6 changes: 3 additions & 3 deletions library/Java/Lang/String/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ int String::indexOf(int character) const {
if (found != std::string::npos) {
return found;
} else {
return NOT_FOUND;
return DO_NOT_FOUND;
}
}

Expand Down Expand Up @@ -314,7 +314,7 @@ int String::lastIndexOf(String subString) const {
std::reverse(currentReversedString.begin(), currentReversedString.end());
std::size_t found = currentReversedString.find(reversedString.original);
if (found == std::string::npos) {
return NOT_FOUND;
return DO_NOT_FOUND;
}
return ((int) this->original.size() - (int) (found + subString.original.size()));
}
Expand All @@ -337,7 +337,7 @@ int String::lastIndexOf(String subString, int fromIndex) const {
std::string reversedString = subString.toCharPointer();
std::reverse(reversedString.begin(), reversedString.end());
int result = subStringFromIndex.find(reversedString);
if (result == NOT_FOUND) {
if (result == DO_NOT_FOUND) {
return result;
}

Expand Down
88 changes: 63 additions & 25 deletions library/Java/Lang/String/StringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,17 @@ TEST (JavaLangString, Destructor) {
auto textPointer = new String("Hello");
delete textPointer;
}
TEST (JavaLangString, getSize) {
//Given a String - Return size of the String
String text = "Hello World";
int sizeOfText = text.getSize();
assertEquals(11, sizeOfText);

//Given a null String
String nullText = "";
assertEquals(0, nullText.getSize());

}
TEST (JavaLangString, Equals) {
// Given two String objects with same value - Return they should equal
String stringEqual1 = "Hello World";
Expand Down Expand Up @@ -520,7 +530,7 @@ TEST (JavaLangString, LastIndexOf) {

// Test false with wrong subString
result = validString.lastIndexOf(wrongString);
assertEquals(NOT_FOUND, result);
assertEquals(DO_NOT_FOUND, result);
}

{
Expand Down Expand Up @@ -611,14 +621,14 @@ TEST (JavaLangString, GetChars) {
Array<char> subCharArray1= {'S','t','r','i','n','g','S','t','r','i','n','g'};

for (int index=0; index<Math::min(subCharArray1.length, charArray.length); index++) {
assertTrue((int) subCharArray1[index] == (int) charArray[index]);
assertTrue((int) subCharArray1[index] == (int) charArray[index]);
}

testString.getChars(10, 16, charArray, 3);
Array<char> subCharArray2 = {'S','t','r','S','t','r','i','n','g', 'i','n','g'};
for (int index=0; index<Math::min(subCharArray2.length, charArray.length); index++) {
assertTrue((int) subCharArray2[index] == (int) charArray[index]);
}
for (int index=0; index<Math::min(subCharArray2.length, charArray.length); index++) {
assertTrue((int) subCharArray2[index] == (int) charArray[index]);
}
}

TEST (JavaLangString, IsEmpty) {
Expand Down Expand Up @@ -852,26 +862,54 @@ TEST (JavaLangString, StartsWith) {
assertFalse(textPlus.startsWith(String("ello")));
}

TEST(JavaLangString, toCharArray){
//Given a string - Return an array of char
String text = "Hello World";
String textResult = "";
int index;
Array<char> arrayOfText = text.toCharArray();
for(index = 0; index < arrayOfText.length; index++) {
textResult += arrayOfText[index];
}
assertEquals("Hello World", textResult);

//Given a null String
String nullText = "";
textResult = "";
Array<char> arrayNull = nullText.toCharArray();
assertEquals("", arrayNull);
}

TEST(JavaLangString, toCharPointer){
String text = "Hello World";
int index;
char* ptrToText = text.toCharPointer();
for(index = 0; index < text.length() ; index++) {

assertEquals(text[index], *(ptrToText + index));
}
}

TEST (JavaLangString, ToLowerCase) {
{
String textPlus = "Hello HELLO Hello ";
String result = textPlus.toLowerCase();
assertEquals("hello hello hello ", result);
}

{
String unicodeString = "Đây Là Tiếng VIỆT";
String result = unicodeString.toLowerCase();
assertEquals("đây là tiếng việt", result);
}
{
String textPlus = "Hello HELLO Hello ";
String result = textPlus.toLowerCase();
assertEquals("hello hello hello ", result);
}

{
String unicodeString = "Đây Là Tiếng VIỆT";
String result = unicodeString.toLowerCase();
assertEquals("đây là tiếng việt", result);
}
}

TEST (JavaLangString, ToUpperCase) {
{
String textPlus = "Hello HELLO Hello ";
String result = textPlus.toUpperCase();
assertEquals("HELLO HELLO HELLO ", result);
}
{
String textPlus = "Hello HELLO Hello ";
String result = textPlus.toUpperCase();
assertEquals("HELLO HELLO HELLO ", result);
}

{
String unicodeString = "Đây Là Tiếng VIỆT";
Expand All @@ -893,10 +931,10 @@ TEST (JavaLangString, Trim) {
assertEquals("đây là tiếng việt", result.toString());
}

{
String trimUpperCase = " this is a cat ";
assertEquals("THIS IS A CAT", trimUpperCase.trim().toUpperCase());
}
{
String trimUpperCase = " this is a cat ";
assertEquals("THIS IS A CAT", trimUpperCase.trim().toUpperCase());
}

{
String allSpaceString = " ";
Expand Down
Loading

0 comments on commit 2481aa1

Please sign in to comment.