Exemplo n.º 1
0
void
StringTest::TestCharString() {
    IcuTestErrorCode errorCode(*this, "TestCharString()");
    char expected[400];
    static const char longStr[] =
        "This is a long string that is meant to cause reallocation of the internal buffer of CharString.";
    CharString chStr(longStr, errorCode);
    if (0 != strcmp(longStr, chStr.data()) || (int32_t)strlen(longStr) != chStr.length()) {
        errln("CharString(longStr) failed.");
    }
    CharString test("Test", errorCode);
    CharString copy(test,errorCode);
    copy.copyFrom(chStr, errorCode);
    if (0 != strcmp(longStr, copy.data()) || (int32_t)strlen(longStr) != copy.length()) {
        errln("CharString.copyFrom() failed.");
    }
    StringPiece sp(chStr.toStringPiece());
    sp.remove_prefix(4);
    chStr.append(sp, errorCode).append(chStr, errorCode);
    strcpy(expected, longStr);
    strcat(expected, longStr+4);
    strcat(expected, longStr);
    strcat(expected, longStr+4);
    if (0 != strcmp(expected, chStr.data()) || (int32_t)strlen(expected) != chStr.length()) {
        errln("CharString(longStr).append(substring of self).append(self) failed.");
    }
    chStr.clear().append("abc", errorCode).append("defghij", 3, errorCode);
    if (0 != strcmp("abcdef", chStr.data()) || 6 != chStr.length()) {
        errln("CharString.clear().append(abc).append(defghij, 3) failed.");
    }
    chStr.appendInvariantChars(UNICODE_STRING_SIMPLE(
        "This is a long string that is meant to cause reallocation of the internal buffer of CharString."),
        errorCode);
    strcpy(expected, "abcdef");
    strcat(expected, longStr);
    if (0 != strcmp(expected, chStr.data()) || (int32_t)strlen(expected) != chStr.length()) {
        errln("CharString.appendInvariantChars(longStr) failed.");
    }
    int32_t appendCapacity = 0;
    char *buffer = chStr.getAppendBuffer(5, 10, appendCapacity, errorCode);
    if (errorCode.isFailure()) {
        return;
    }
    memcpy(buffer, "*****", 5);
    chStr.append(buffer, 5, errorCode);
    chStr.truncate(chStr.length()-3);
    strcat(expected, "**");
    if (0 != strcmp(expected, chStr.data()) || (int32_t)strlen(expected) != chStr.length()) {
        errln("CharString.getAppendBuffer().append(**) failed.");
    }
}
Exemplo n.º 2
0
void WdmChMapComponent::getMappedNames()
{
	int devChMappedTo = 0;		// index into the list of aggregated channels of all bus devices
	uint32 speakerBits = 0;		// bitmap bits correspond to speaker positions, as defined in ksmedia.h
	int numDevChs = 0;

	tcat::dice::bus_impl::channel_list channels;	// deque containing device names for all aggregated channels of all bus devices

	if (m_bus)
	{
		if (m_out)
		{
			// output channels	
			channels = m_bus->channels(true);
			numDevChs = (int)channels.size();

			m_out_map_names.clear();
			// using set() to initially reserve the array, modify therafter
			for (int i=0; i<(int)numDevChs; i++)
			{
				m_out_map_names.set(i, " -");	// unmapped
			}
			
			// get the speaker positions present in the current speaker setup
			speakerBits = m_bus->speaker();

			// build the wdm name
			for (int chn=0; chn<kTCAT_DICE_MAX_WDM_IN_CHANNELS; chn++)
			{
				String nameStr;
				nameStr << "WDM " << (chn+1); // show 1-based numbering

				// add a wdm speaker name if present in speaker map
				int count = 0;
				for (int pos=0; pos<32; pos++)
				{
					if (speakerBits & (1<<pos))
					{
						if (count == chn)
						{
							nameStr << " (" << m_wdm_names[pos] << ")";
							break;
						}
						count++;
					}
				}
				devChMappedTo = m_bus->speaker_map(true, chn);
				if (devChMappedTo>=0)
				{
					m_out_map_names.set(devChMappedTo, nameStr);
				}
			}
		}
		else
		{
			// input channels	
			channels = m_bus->channels(false);
			numDevChs = (int)channels.size();

			m_in_map_names.clear();
			// using set() to initially reserve the array, modify therafter
			for (int i=0; i<(int)numDevChs; i++)
			{
				m_in_map_names.set(i, " -");		// unmapped
			}

			for (int i=0; i<kTCAT_DICE_MAX_WDM_IN_CHANNELS; i++)
			{
				devChMappedTo = m_bus->speaker_map(false, i);
				if ((devChMappedTo >= 0) && (devChMappedTo < numDevChs))
				{
					String chStr(String::empty);
					chStr << "WDM " << (i+1);	// convert to 1-based numbering
					m_in_map_names.set(devChMappedTo, chStr);
				}
			}
		}
	}
}