mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-11-03 14:33:37 +03:00 
			
		
		
		
	* add stubs for more exception throw calls Fixes https://github.com/esp8266/Arduino/issues/3358 * libc: make putc_r implementation weak newlib provides its own implementation of _putc_r, which will call _write_r (possibly after buffering). Make our implementation weak to allow using the one from newlib. Fixes https://github.com/esp8266/Arduino/issues/4630 * libc: fix incorrect return value of _write_r call Should return number of bytes written, actually returned zero. This resulted in std::cout going into failed state after the first write. * tests: add test for output to std::cout
		
			
				
	
	
		
			35 lines
		
	
	
		
			712 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			712 B
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <ESP8266WiFi.h>
 | 
						|
#include <BSTest.h>
 | 
						|
#include <sstream>
 | 
						|
#include <iostream>
 | 
						|
 | 
						|
BS_ENV_DECLARE();
 | 
						|
 | 
						|
void setup()
 | 
						|
{
 | 
						|
    Serial.begin(115200);
 | 
						|
    BS_RUN(Serial);
 | 
						|
}
 | 
						|
 | 
						|
TEST_CASE("can print to std::cout", "[iostream]")
 | 
						|
{
 | 
						|
    std::stringstream test_stream("");
 | 
						|
    test_stream << "hello stream";
 | 
						|
 | 
						|
    // empty the RX buffer, just in case
 | 
						|
    Serial.readString();
 | 
						|
 | 
						|
    USC0(0) |= (1 << UCLBE);  // enable loopback
 | 
						|
    std::cout << test_stream.str().c_str() << std::endl;
 | 
						|
    delay(100);
 | 
						|
    USC0(0) &= ~(1 << UCLBE);  // disable loopback
 | 
						|
    
 | 
						|
    String result = Serial.readStringUntil('\n');
 | 
						|
 | 
						|
    Serial.printf("result: '%s'\n", result.c_str());
 | 
						|
 | 
						|
    CHECK(result == test_stream.str().c_str());
 | 
						|
}
 | 
						|
 | 
						|
void loop() { }
 |