aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/os/users.moon31
1 files changed, 28 insertions, 3 deletions
diff --git a/test/unit/os/users.moon b/test/unit/os/users.moon
index 366407d5c8..2f08bdbdf5 100644
--- a/test/unit/os/users.moon
+++ b/test/unit/os/users.moon
@@ -12,6 +12,9 @@ typedef struct growarray {
void *ga_data;
} garray_T;
int mch_get_usernames(garray_T *usernames);
+int mch_get_user_name(char *s, size_t len);
+int mch_get_uname(int uid, char *s, size_t len);
+int getuid(void);
]]
NULL = ffi.cast 'void*', 0
@@ -30,10 +33,10 @@ garray_get_item = (array, index) ->
describe 'users function', ->
- describe 'mch_get_usernames', ->
+ -- will probably not work on windows
+ current_username = os.getenv 'USER'
- -- will probably not work on windows
- current_username = os.getenv 'USER'
+ describe 'mch_get_usernames', ->
it 'returns FAIL if called with NULL', ->
eq FAIL, users.mch_get_usernames NULL
@@ -50,3 +53,25 @@ describe 'users function', ->
current_username_found = true
assert.is_true current_username_found
+ describe 'mch_get_user_name', ->
+
+ it 'should write the username into the buffer and return OK', ->
+ name_out = ffi.new 'char[100]'
+ eq OK, users.mch_get_user_name(name_out, 100)
+ eq current_username, ffi.string name_out
+
+ describe 'mch_get_uname', ->
+
+ it 'should write the username into the buffer and return OK', ->
+ name_out = ffi.new 'char[100]'
+ user_id = lib.getuid!
+ eq OK, users.mch_get_uname(user_id, name_out, 100)
+ eq current_username, ffi.string name_out
+
+ it 'should FAIL if the userid is not found', ->
+ name_out = ffi.new 'char[100]'
+ -- hoping nobody has this uid
+ user_id = 2342
+ eq FAIL, users.mch_get_uname(user_id, name_out, 100)
+ eq '2342', ffi.string name_out
+