ICU-8432 test & document that PluralRules::getSamples() returns count<=destCapacity

X-SVN-Rev: 29924
This commit is contained in:
Markus Scherer 2011-04-29 16:42:34 +00:00
parent 5d6b488406
commit bb9af46cfe
2 changed files with 24 additions and 13 deletions

View file

@ -156,7 +156,7 @@ public:
/**
* Creates a PluralRules from a description if it is parsable, otherwise
* returns null.
* returns NULL.
*
* @param description rule description
* @param status Output param set to success/failure code on exit, which
@ -250,7 +250,7 @@ public:
*
* @param keyword The keyword.
* @param dest Array into which to put the returned values. May
* be null if destCapacity is 0.
* be NULL if destCapacity is 0.
* @param destCapacity The capacity of the array, must be at least 0.
* @param status The error code.
* @return The count of values available, or -1. This count
@ -258,8 +258,9 @@ public:
* destCapacity values will be written.
* @draft ICU 4.8
*/
int32_t getAllKeywordValues(const UnicodeString &keyword, double *dest,
int32_t destCapacity, UErrorCode& status);
int32_t getAllKeywordValues(const UnicodeString &keyword,
double *dest, int32_t destCapacity,
UErrorCode& status);
/**
* Returns sample values for which select() would return the keyword. If
@ -269,16 +270,19 @@ public:
*
* @param keyword The keyword.
* @param dest Array into which to put the returned values. May
* be null if destCapacity is 0.
* be NULL if destCapacity is 0.
* @param destCapacity The capacity of the array, must be at least 0.
* @param status The error code.
* @return The count of values available, or -1 if error.
* This can be larger than destCapacity, but no
* more than destCapacity values will be written.
* @return The count of values written.
* If more than destCapacity samples are available, then
* only destCapacity are written, and destCapacity is returned as the count,
* rather than setting a U_BUFFER_OVERFLOW_ERROR.
* (The actual number of keyword values could be unlimited.)
* @draft ICU 4.8
*/
int32_t getSamples(const UnicodeString &keyword, double *dest,
int32_t destCapacity, UErrorCode& status);
int32_t getSamples(const UnicodeString &keyword,
double *dest, int32_t destCapacity,
UErrorCode& status);
/**
* Returns TRUE if the given keyword is defined in this

View file

@ -17,6 +17,8 @@
#include "plurults.h"
#include "unicode/plurrule.h"
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof(array[0]))
void setupResult(const int32_t testSource[], char result[], int32_t* max);
UBool checkEqual(PluralRules *test, char *result, int32_t max);
UBool testEquality(PluralRules *test);
@ -392,15 +394,20 @@ void PluralRulesTest::testGetSamples() {
while (NULL != (keyword = keywords->snext(status))) {
int32_t count = rules->getSamples(*keyword, values, 4, status);
if (U_FAILURE(status)) {
errln(UNICODE_STRING_SIMPLE("get samples failed for locale ") + locales[i].getName() +
errln(UNICODE_STRING_SIMPLE("getSamples() failed for locale ") +
locales[i].getName() +
UNICODE_STRING_SIMPLE(", keyword ") + *keyword);
continue;
}
if (count == 0) {
errln("no samples for keyword");
}
if (count > 4) { // count is number available, not number we wrote...
count = 4;
if (count > LENGTHOF(values)) {
errln(UNICODE_STRING_SIMPLE("getSamples()=") + count +
UNICODE_STRING_SIMPLE(", too many values, for locale ") +
locales[i].getName() +
UNICODE_STRING_SIMPLE(", keyword ") + *keyword);
count = LENGTHOF(values);
}
for (int32_t j = 0; j < count; ++j) {
if (values[j] == UPLRULES_NO_UNIQUE_VALUE) {