-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update memory handling and pointer size calculations
Replaced string-based memory allocation with UTF-8 encoded byte arrays for better compatibility and precision. Adjusted key and value length calculations to use the size of pointers instead of string lengths, ensuring correctness when working with native libraries. These changes improve robustness and prevent potential errors in memory operations.
- Loading branch information
Showing
7 changed files
with
151 additions
and
30 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
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
67 changes: 67 additions & 0 deletions
67
src/jvmCommonTest/kotlin/com/github/lamba92/leveldb/tests/UTF16Tests.kt
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,67 @@ | ||
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING", "unused") | ||
|
||
package com.github.lamba92.leveldb.tests | ||
|
||
import kotlin.test.assertEquals | ||
|
||
@Target(AnnotationTarget.FUNCTION) | ||
expect annotation class Test() | ||
|
||
class UTF16Tests { | ||
@Test | ||
fun emoji() = withDatabase { db -> | ||
val key = "👋🌍" | ||
val value = "👋🌍" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
|
||
@Test | ||
fun accentedChars() = withDatabase { db -> | ||
val key = "áéíóú" | ||
val value = "áéíóú" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
|
||
@Test | ||
fun chineseChars() = withDatabase { db -> | ||
val key = "你好" | ||
val value = "你好" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
|
||
@Test | ||
fun japaneseChars() = withDatabase { db -> | ||
val key = "こんにちは" | ||
val value = "こんにちは" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
|
||
@Test | ||
fun cyrillicChars() = withDatabase { db -> | ||
val key = "Здравствуйте" | ||
val value = "Здравствуйте" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
|
||
@Test | ||
fun dieresis() = withDatabase { db -> | ||
val key = "äëïöü" | ||
val value = "äëïöü" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
|
||
@Test | ||
fun greekChars() = withDatabase { db -> | ||
val key = "Γειά σας" | ||
val value = "Γειά σας" | ||
db.put(key, value) | ||
assertEquals(value, db.get(key)) | ||
} | ||
} | ||
|
4 changes: 4 additions & 0 deletions
4
src/jvmTest/kotlin/com/github/lamba92/leveldb/tests/ApiTests.jvm.kt
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") | ||
|
||
package com.github.lamba92.leveldb.tests | ||
|
||
actual val DATABASE_PATH: String | ||
get() = | ||
System.getenv("LEVELDB_LOCATION") | ||
?: error("LEVELDB_LOCATION environment variable not set") | ||
|
||
actual typealias Test = org.junit.jupiter.api.Test |