Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-26149] Android: Ti.Filesystem.File#getDirectoryListing() does not return null for file/non-existent directory #10128

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public boolean getHidden()
public String[] getDirectoryListing()
// clang-format on
{
if (!isDirectory()) {
return null;
}
List<String> dl = tbf.getDirectoryListing();
return dl != null ? dl.toArray(new String[0]) : null;
}
Expand Down
65 changes: 65 additions & 0 deletions tests/Resources/ti.filesystem.file.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions'); // eslint-disable-line no-unused-vars

describe('Titanium.Filesystem.File', function () {
describe('#getDirectoryListing()', function () {
it('is a Function', function () {
var dir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory);
should(dir.getDirectoryListing).be.a.Function;
});

it('returns Array of filenames for directory contents', function () {
var dir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory),
files = dir.getDirectoryListing();
should(dir.exists()).be.true;
files.should.be.an.Array;
files.length.should.be.above(0);
files[0].should.be.a.String;
});

it('returns empty Array for empty directory', function () {
var emptyDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'emptyDir'),
result;
should(emptyDir).be.ok;
// remove it if it exists
if (emptyDir.exists()) {
should(emptyDir.deleteDirectory()).eql(true);
}
// create a fresh empty dir
should(emptyDir.createDirectory()).eql(true);
should(emptyDir.exists()).eql(true);
should(emptyDir.isFile()).eql(false);
should(emptyDir.isDirectory()).eql(true);

result = emptyDir.getDirectoryListing();
result.should.be.an.Array;
result.length.should.eql(0);
});

it('returns null for non-existent directory', function () {
var nonExistentDir = Ti.Filesystem.getFile('madeup');
var result = nonExistentDir.getDirectoryListing();
should(nonExistentDir).be.ok;
should(nonExistentDir.exists()).eql(false);
should(result).eql(null);
});

it('returns null for file', function () {
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'app.js');
var result = file.getDirectoryListing();
should(file).be.ok;
should(file.exists()).eql(true);
should(file.isFile()).eql(true);
should(result).eql(null);
});
});
});